Questions tagged [ocunit]

OCUnit is a unit testing framework for the Objective-C language and included with Apple's Xcode IDE since Xcode 2.1.

OCUnit is a unit testing framework for the Objective-C language and included with Apple's Xcode IDE since Xcode 2.1.

It was created by Sen:te and modeled after the original Smalltalk unit testing framework. In design and use it is similar to classical JUnit, but taking advantage of Objective-C's runtime features to automatically locate tests to run.

263 questions
63
votes
7 answers

Unit Testing of private methods in Xcode

I'm trying out test driven development in a toy project. I can get the tests working for the public interface to my classes (although I'm still on the fence because I'm writing more testing code than there is in the methods being tested). I tend to…
Abizern
  • 129,329
  • 36
  • 198
  • 252
51
votes
4 answers

Link error while building a unit test target

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…
cfischer
  • 23,024
  • 36
  • 125
  • 209
47
votes
5 answers

Xcode 4: Run tests from the command line (xcodebuild)?

I've created a brand new iOS project in Xcode 4, and included unit tests. The default app has 2 targets, the main application and the unit test bundle. Using "Product > Test" (Command-U) builds the application, builds the unit test bundle, launches…
Steven Wisener
  • 471
  • 1
  • 5
  • 4
40
votes
5 answers

XCTAssertEqual error: ("3") is not equal to ("3")

NSMutableArray *arr = [NSMutableArray array]; [arr addObject:@"1"]; [arr addObject:@"2"]; [arr addObject:@"3"]; // This statement is fine. XCTAssertTrue(arr.count == 3, @"Wrong array size."); // This assertion fails with an error: ((arr.count)…
Sergey
  • 39,828
  • 24
  • 80
  • 122
39
votes
1 answer

OCUnit & NSBundle

I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test: // myClass.h #import #import @interface myClass : NSObject { UIImage *image; } @property…
kpower
  • 3,851
  • 4
  • 41
  • 62
39
votes
1 answer

Unit Testing Example with OCUnit

I'm really struggling to understand unit testing. I do understand the importance of TDD, but all the examples of unit testing I read about seem to be extremely simple and trivial. For example, testing to make sure a property is set or if memory is…
mnort9
  • 1,788
  • 3
  • 28
  • 51
36
votes
2 answers

Xcode : One test target for multiple app targets

I am wondering if you can link one Unit Testing bundle to multiple targets. So one can test all the application targets with one Testing bundle. I have some shared code between all app targets but also some specific calculations based upon which app…
Yannick
  • 1,026
  • 1
  • 11
  • 23
35
votes
2 answers

How do I migrate from SenTestingKit/OCUnit to XCTest?

I am in the process of migrating my project from Xcode 4.6.3 to Xcode 5.0.2. The project's unit tests were developed with SenTestingKit/OCUnit. Now when I am running the tests in Xcode 5, I get an error from the RunUnitTests script telling me…
herzbube
  • 12,320
  • 8
  • 42
  • 76
31
votes
7 answers

Run logic tests in Xcode 4 without launching the simulator

I want to run tests in Xcode 4 using OCUnit without launching the simulator. Please, don't try and convince me I am doing unit testing wrong or anything like that. I like to do TDD the traditional way: write the API for the class in the tests, then…
Jez Humble
  • 411
  • 4
  • 5
28
votes
3 answers

iPhone - Retrieving Resources for logical unit tests

I've been following Apple's documentation on writing unit tests for the iPhone, and out of the box, the routine doesn't seem to work. I'm not sure I understand where the unit test is going to get the reference to the application delegate. My…
Gary
  • 1,515
  • 1
  • 14
  • 22
27
votes
3 answers

Unit tests for memory management in Cocoa/Objective-C

How would you write a unit test—using OCUnit, for instance—to ensure that objects are being released/retained properly in Cocoa/Objective-C? A naïve way to do this would be to check the value of retainCount, but of course you should never use…
Chris Frederick
  • 5,112
  • 3
  • 34
  • 40
27
votes
7 answers

Some of my unit tests tests are not finishing in XCode 4.4

I have seen people posting about this here and elsewhere, but I haven't found any solution that works. I am using XCode 4.4 and have a bunch of unit tests set up. I have ran them all before on this project, so I know that they do pass/fail when they…
Logan Serman
  • 27,645
  • 25
  • 100
  • 139
25
votes
2 answers

Xcode warning "profiling: invalid magic number"

I just installed Xcode 4.6. When I run my OCUnit tests now, I get multiple lines with "profiling: invalid magic number" in the output window after all tests have finished. I'm pretty sure that Xcode 4.5.2 didn't give me that output. Does anybody…
Dorian Roy
  • 2,926
  • 2
  • 28
  • 49
24
votes
2 answers

OCUnit test for protocols/callbacks/delegate in Objective-C

Using OCUnit, is there a way to test delegate protocols? I'm trying this, which doesn't work. -(void) testSomeObjDelegate { SomeObj obj = [[SomeObj alloc] initWithDelegate:self]; [obj executeMethod]; } -(void) someObjDelegateMethod { //test…
N355A
  • 268
  • 1
  • 2
  • 5
23
votes
1 answer

Linking error for unit testing with XCode 4?

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…
shadowmatter
  • 1,292
  • 1
  • 18
  • 30
1
2 3
17 18