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
22
votes
7 answers

What is the proper way to detect if unit tests are running at runtime in Xcode?

When I'm running unit tests, I'd like to skip some code (e.g. I don't want [[UIApplication sharedApplication] openURL:..] to run). I'm looking for a runtime check if I'm currently running units tests or not. I know I have seen code that checks the…
Ronald Mannak
  • 446
  • 1
  • 4
  • 11
21
votes
3 answers

What's the quickest way to compare a NSUInteger with an int (e.g. 5) in objective-c?

What's the quickest way to compare a NSUInteger with an int (e.g. 5) in objective-c? Background - I'm noting that the following line of code gives an error: STAssertEquals([nsMutableArrayInstance count], 5, @"xxxx"); // gives Type Mismatch So what…
Greg
  • 34,042
  • 79
  • 253
  • 454
20
votes
3 answers

iOS unit test: How to set/update/examine firstResponder?

How do you write first responder unit tests? I'm trying to write a test to confirm that a method advances focus to the next text field. controller is a descendant of UIViewController. But this exploratory test fails: - (void)testFirstResponder { …
Jon Reid
  • 20,545
  • 2
  • 64
  • 95
18
votes
6 answers

OCUnit tests to existing iOS project. "ld: file not found"

I've been following this blog post: Adding unit tests to existing project. I'm getting this error however: ld: file not found: Build/Products/Debug-iphoneos/MyApp.app/MyApp Command …
Sam
  • 1,042
  • 2
  • 8
  • 19
18
votes
9 answers

Xcode 4 unit testing linker error

NOTE: "Use GHUnit" is not an acceptable answer to this question. I know most think GHUnit is better than the Xcode4 OCUnit, but that's not what I'm asking about. I'll evaluate that separately. I have an Xcode project that I created in Xcode4 from…
Kongress
  • 2,244
  • 3
  • 20
  • 30
18
votes
2 answers

How do you load a prototype cell from a storyboard?

Is there a way to load a prototype cell, along with any IBOutlet connections as defined within a storyboard? Update I want to unit test the cell (a UICollectionViewCell for that mater), hence would like to load it outside of a UIViewController…
qnoid
  • 2,346
  • 2
  • 26
  • 45
18
votes
2 answers

How can I unit test a Core Data migration?

I'm building a mapping model for my migration with a custom entity migration policy, and I'd really like to build some unit tests for this migration. The migration seems to work correctly when I run the app, but my NSEntityMigrationPolicy subclass…
Greg
  • 10,360
  • 6
  • 44
  • 67
17
votes
5 answers

Unit Test can't find Core Data model file

I've created a project with a Core Data model in it. The application looks for the model file (.momd) and runs just fine. Unfortunately, the unit test keeps returning null: NSURL *dataModelURL = [[NSBundle mainBundle] URLForResource:@"myDataModel"…
Luther Baker
  • 7,236
  • 13
  • 46
  • 64
16
votes
2 answers

How to run and debug unit tests for an iPhone application

NOTE: Unit testing is a lot easier to setup nowadays. This tutorial is not really relevant for Xcode version 5 and above. It took me quite some time but I finally managed to make it work for my project. To create the "logic" tests I followed Apple…
MiKL
  • 1,850
  • 1
  • 15
  • 23
15
votes
4 answers

Occasional errors when running OCUnit application test suite on device

I'm having some problems with my OCUnit test suite, when running application tests (i.e. on the device). Occasionally, I get a tricky error that seems to be thrown from the OCUnit classes. I've been trying to look through the files added to the test…
Kristofer Sommestad
  • 3,061
  • 27
  • 39
15
votes
5 answers

Why doesn't gcov report any lines being covered by my unit tests?

I am using Xcode 3.2 on 10.6, with the shipped version of gcov and default GCC compiler (both version 4.2.1). I have created a dependent Cocoa unit test bundle which is injected into my app, and followed Apple's documentation on setting up a…
user23743
15
votes
3 answers

EXC_BAD_ACCESS when accessing parameters in andDo of 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…
UrK
  • 2,191
  • 2
  • 26
  • 42
14
votes
2 answers

isKindOfClass and NSStringFromClass disagree about UIApplicationDelegate

I was playing with a simple OCUnit test for an iPhone app, and just wanted to assert that the app delegate was an instance of the class that I expected it to be. I didn't expect this test to be very useful, but it turned out to reveal a…
pohl
  • 3,158
  • 1
  • 30
  • 48
14
votes
4 answers

Is it possible to unit test a static library project using XCode's SenTestingKit?

I've created an iOS unit test target for doing logic tests following the steps provided in Apple's documentation. However my build fails and i get the following error: Undefined symbols: "_OBJC_CLASS_$_MyClass", referenced from: …
Patrick
  • 1,079
  • 1
  • 9
  • 14
14
votes
2 answers

SSL Connections Issues when running Unit Tests from the command line

Goal Our goal is to execute our Unit Tests within a Continuous Integration environment (Jenkins) (I believe it is essential for every question to state what exactly one is trying to achieve. Maybe the problem can actually be solved a very different…
below
  • 929
  • 6
  • 26
1
2
3
17 18