problem about ocunit-Collection of common programming errors
Vladimir
objective-c ocunit
What is the correct way to check the NSArray items count with STAssertEquals for NSArray.Following was expected to work:… STAssertEquals(1, [myArray count], @”One item should be in array”);This code produces “Type mismatch” runtime error when running test.Instead I have to do an explicit cast to NSUInteger:STAssertEquals((NSUInteger)1, [myArray count], @”One item should be in array”);This works – but looks kind a ugly due to explicit cast.I also want to avoid using STAssertTrue because STAsser
Jon Reid
ios unit-testing core-data ocunit ocmock
I am trying to write unit tests for a view controller that implements the NSFetchedResultsControllerDelegate protocol. The first test of the implementation (after some other tests of this view controller) is to verify that a table row is inserted into the table view when a new object is inserted.My first implementation of the test was:- (void) setUp {[super setUp];sut = [[JODataTableViewController alloc] init];fetchedResultsCtrlrMock = [OCMockObject niceMockForClass:[NSFetchedResultsController c
Ilea Cristian
ios ocunit ocmock
I have a test that verifies (with OCMock) that a method gets called when a certain notification is sent:- (void)testThatVCRegistersToLocationUpdateNotification {IssueDetailsViewController* vc = [[IssueDetailsViewController alloc] init];id mockVC = [OCMockObject partialMockForObject:vc];[[mockVC expect] locationDidUpdate:[OCMArg any]];[vc viewDidLoad];[[NSNotificationCenter defaultCenter] postNotificationName:LOCATION_DID_UPDATE object:nil];[mockVC verify]; }This is the error:error: testThatVCReg
Toran Billups
iphone objective-c ocunit ocmock
I’m writing a test to verify location services are started when a button click occurs. This requires a very simple if statement to make sure the phone has location services available.A working test right now looks like this- (void)testStartUpdatingLocationInvokedWhenLocationServicesAreEnabled {[[[self.locationManager stub] andReturnValue:[NSNumber numberWithBool:true]] locationServicesEnabled];[[self.locationManager expect] startUpdatingLocation];[self.sut buttonClickToFindLocation:nil];[self.lo
abbood
ios objective-c xcode5 ocunit ocmock
I know that OCMock version 2.1+ supports stubbing class methods out of the box. But for some reason it’s not working with me. To make sure I isolated the problem, I simply cloned the example OCMock project (which is clearly marked as version 2.2.1) and simply added this inside testMasterViewControllerDeletesItemsFromTableView:id detailViewMock = [OCMockObject mockForClass:[DetailViewController class]]; [[[detailViewMock stub] andReturn:@”hello”] helloWorld]; in DetailViewController.h I added: +
Greg
iphone ios xcode4 ocunit
I’m using Unit Testing in XCode 4. I’ve been adding my application *.m files to the unit test target “compile sources” as I refer to them so the unit test will build/run.Is there a better way here? Note – I’ve just tried adding the application to the unit test target “target dependencies”, but this didn’t seem to work (still get some build errors).
Joe
objective-c unit-testing xcode memory-management ocunit
I’m currently trying to learn objective-c using XCode 3.1. I’ve been working on a small program and decided to add unit testing to it. I followed the steps on the Apple Developer page – Automated Unit Testing with Xcode 3 and Objective-C. When I added my first test, it worked fine when the tests failed, but when I corrected the tests the build failed. Xcode reported the following error:error: Test host ‘/Users/joe/Desktop/OCT/build/Debug/OCT.app/Contents/MacOS/OCT’ exited abnormally with code
Gabriel Candia
xcode jenkins jenkins-plugins ocunit
I’m having a huge problem trying to run the unit testing with the iphoneos, i need this because some of the framework that i`m using doesn´t run in the simulator, so if i try to run the unit test in the simulator it crash. I can run the unit testing in the xcode directly to the device but when i try to do that with Jenkins i can´t figure it out how. I’m using Jenkins with the Xcode plugin to run the test.Is there a way to run the test using the iphoneos SDK and not the iphonesimulator?.Hope you
Vilém Kurz
ios xcode4 ocunit
It seems, that I have everything setup right. When I run command-u (or pick product – test from menu) test run fine.Best practices should be, that test should run as often as possible, ideally during each build (understand during each run).How to force XCode 4 to do it? I have tried to:setup target dependency (put main app target to be dependent on test target) enable “test after build” in main app target build settings tick also test target in scheme editor for run main app schemebut nothing se
greenisus
objective-c unit-testing ocunit
I know how to resolve EXC_BAD_ACCESS issues, but I’m not sure how to unit test for it. Is there a way to capture EXC_BAD_ACCESS in code instead of simply crashing?Here’s why I ask: I have written a library that heavily uses blocks, like this:- (void)doSomething:(void (^)())myBlock;In my implementation of doSomething: I’m going to eventually run the block, like this:myBlock();If a caller passes nil for the block, then it will crash with EXC_BAD_ACCESS, so the solution is to check that the block
John M
cocoa xcode ocunit
XCode 3.1.2 using built-in OCTest unit testing.I’m getting a crash when unit tests run. I want to run w/ a few extra environment variables (MallocCheckHeapStart, MallocCheckHeapEach, for example).I’m a beginner with this and can’t figure out how to run my app’s OCTest unit tests from the command-line. Or alternatively, to convince XCode to set a few extra environment variables when it launches the unit tests.
UrK
iphone ios xcode ocunit ocmock
I am trying to write an block of code using OCMock’s stub andDo method.In this case UIImageView extension class is being tested. I want to check that the extension calls [self setImage:] with parameter that is non-nil (later other image comparison will be used).When using OCMock’s andDo method, the test crashes with EXC_BAD_ACCESS after the block completes.id mockView = [OCMockObject mockForClass:[UIImageView class]]; [[[mockView stub] andDo:^(NSInvocation *invocation){UIImage *img;[invocation g
Adrian Petrescu
iphone objective-c osx ocunit error-code
Does anyone know how to find a list of all the possible error codes thrown by the ostest utility, and their meanings? I noticed this to be a common problem for people, where they ask about an OCUnit failure with some code 138 or 139 that is completely opaque to them, and somebody who has encountered that particular error number points out an obvious problem which the asker could have easily identified if they knew what to look for.But Google, ADC, and the man pages all seem to be silent about th
Jon Reid
ios tdd ocunit ocmock
I’m setting up a mock object for a delegate object, to check that when the URL is nil, the delegate method is called with nil as parameters.When the FileDownloadOperation behave as expected,the test pass, which is fine.When the FileDownloadOperation doesn’t call the delegate method, the test fails as expected.But when the FileDownloadOperation calls the delegate method with something else than nil, instead of failing, the test crashes and no other tests are executed because OCMock throws :’NSIn
Edgar Nunez
objective-c ios unit-testing ocunit
A class I wrote is crashing my test case with error code 138. The class returns an NSString with the user agent string from UIWebView:@interface MyWebViewUserAgent : NSObject <UIWebViewDelegate> {NSString* userAgent;UIWebView* webView; }- (NSString*) userAgentString;@end#import “MyWebViewUserAgent.h”@implementation MyWebViewUserAgent- (NSString*) userAgentString {if (userAgent != nil) return userAgent;webView = [[UIWebView alloc] init];webView.delegate = self;[webView loadRequest: [NSURLRe
stokastic
objective-c ios xcode ocunit sentestingkit
I have the following stupidly simple test case (defined in a .mm file with correspong .h file). It uses boost to try to read in a ptree from a stringstream to simulate the text that would be in a file.-(void)setUp {printf(“setup\n”);::std::stringstream ss;ss << “bad format text”;_configuration = new ptree();::boost::property_tree::read_json(ss, *_configuration); }The tearDown function does nothing, and there is one test case, which also does nothing. If I comment out the read_json line, ev
Jon Reid
xcode cocoa unit-testing testing ocunit
In Xcode, at the end of my unit tests I get a result like this:Test Suite ‘All tests’ finished at 2012-12-06 10:23:38 +0000Executed 195 tests, with 0 failures (0 unexpected) in 4.314 (4.485) secondsI would love to find out how can I define tests with expected failures.Normally with other test frameworks I like being able to just define incomplete unit tests as reminders of future work that must be done. These tests should be logged only as warnings, but still yield a “Success” final result if ev
yonix
xcode unit-testing ocunit
I’m using the built-in Unit Testing mechanism in Xcode (OCUnit/SenTest).I find it very upsetting that whenever there’s an exception thrown during a test, instead of moving on and running the next tests, Xcode crashes the run (stopping the debugger on the line of the thrown exception, and marks the tests as successful after crashing!).Is there any way of making the test target just mark the test that raised an exception as failed and move on?BTW, please don’t bother telling me to move to GHUnit,
ziad tamim
iphone cocoa-touch ipad ocunit gh-unit
I’m using GHUnit in my project but when i try to run the app it gives errors Ld /Users/goldfire/Library/Developer/Xcode/DerivedData/WhatsMySpeed-amkgqintxyhelabqvrpouivmdglf/Build/Products/Debug-iphonesimulator/GHUnitTests.app/GHUnitTests normal i386cd /Users/goldfire/Desktop/Example/WhatsMySpeedsetenv MACOSX_DEPLOYMENT_TARGET 10.6setenv PATH “/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bi
Dschee
ios xcode core-data ocunit
OK, here’s my code in my test class:- (NSManagedObjectContext*)managedObjectContextWithConcurrencyType:(NSManagedObjectContextConcurrencyType)concurrencyType {NSManagedObjectModel *mom = [NSManagedObjectModel mergedModelFromBundles:nil];STAssertNotNil(mom, @”Can not create MOM from main bundle”);NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];STAssertNotNil(psc, @”Can not create persistent store coordinator”);NSPersistentStore *store = [p
shadowmatter
objective-c xcode unit-testing linker ocunit
I want to write some logic unit tests for classes in my XCode application. In Xcode 4, I clicked on the project name in the Project Navigator, and from the bottom clicked Add Target. I chose “Cocoa Touch Unit Testing Bundle” under Other, give the new target a “product name” of “tests”, and finish. Because the class I want to test is compiled as part of my existing application target, for my new “tests” target I immediately go to the Build Phases tab and add my existing application target as the
Heath Borders
objective-c ios ocunit
I have an Application Test included in my OCUnit target. I can call instance methods on classes in my Application Host target, but I cannot call class methods. If I call a class method (like alloc), I get the following linker error:Undefined symbols for architecture armv6:”_OBJC_CLASS_$_DiceGameViewController”, referenced from:objc-class-ref in DiceGameViewControllerTest.o(maybe you meant: _OBJC_CLASS_$_DiceGameViewControllerTest) ld: symbol(s) not found for architecture armv6 collect2: ld ret
Brad Larson
ios automatic-ref-counting exc-bad-access ocunit
I have an issue where I’m getting bad access exceptions but only when running a testing build (calling the same methods in a debug build doesn’t cause the problem to come up). The project has ARC enabled and I’m running this on the iPad 5.1 simulator using Xcode 4.3:Here’s where the problem crops up:- (void)testChangeFoodNotification {Player* p = [[Player alloc] init];[p addObserver:self forKeyPath:@”food” options:0 context:0]; // <-EXC_BAD_ACCESS (code=2)p.food += 1;STAssertTrue(_wasNotified
Fernando
unit-testing xcode4 linker-error ocunit
I have a XCode4 / iOS project with a regular target and unit test target. Everything works fine, except when I try to #import one of my classes in my test class and try to use it. If I try to build the unit test target, I get the following link error:Undefined symbols for architecture i386:”_OBJC_CLASS_$_FRRCategory”, referenced from:objc-class-ref in CategoryTests.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit statusIn CategoryTests.m I’m importing the header file
StudentX
ios objective-c xcode4.5 ocunit
If I create a new project which includes unit tests, the test cases get called. But when I’m adding tests to an existing project I’m getting the following in the log:2013-05-21 19:41:08.814 otest[51593:7e03] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size Test Suite ‘/Users/impadmin/Library/Developer/Xcode/DerivedData/SmartDiary-frrybdtgyyjgewbialqsmxkwvlxs/Build/Products/Debug-iphonesimulator/testSmartDiary.octest(Tests)’started at 2013-05-21 14:11:09 +0000Test Suite ‘
Kam Sheffield
ios unit-testing continuous-integration ocunit sfhfkeychainutils
I’m using SFHFKeychainUtils to use Keychain Services in my app. I’ve written some OCUnit tests that verify the funcionality of this code. Everything works fine when I run the unit tests from Xcode on the iOS simulator or my device. However now I’m trying to set up a CI server and the test is failing when it is run via the command line with error code -25291. Looking that up on Apple’s documentation tells me: No trust results are available (errSecNotAvailable). I’ve linked the Security.framework
Web site is in building