views:

54

answers:

2

I am trying to get OCUnit to do anything on my project, but I am failing :-( Is there any good tutorial out there to get it work? Everything I find tells something different and they are all pretty complicated ...

What I tried is e.g.

  1. set up a Unit Testing Target
  2. add my Target as dependency
  3. add a xxTest.m to my unit target and write a testcase like:

code:

#import <SenTestingKit/SenTestingKit.h>

@interface XTest : SenTestCase {
}
@end

@implementation XTest
- (void)testAuthentication {
 STFail(@"fail");
}

@end

The result is, a build success ... What do I have to do to get unit testing working ?

+1  A: 

This question has been asked before: http://stackoverflow.com/questions/33207/what-is-the-best-way-to-unit-test-objective-c-code

All of the information you need can be found here: http://developer.apple.com/tools/unittest.html

Google provides a library of useful code for iPhone developers which also includes an alternative testing framework. Some like it better than the OCUnit that is included with Xcode: http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting

Paul
That doesn't quite answer my questions - I need a tutorial how to get OCUnit for iPhone working - which it does not do for me :-(
RRZ Europe
@RRZ Europe - I'd recommend reading Chris Hanson's articles, which are linked to in the accepted answer on that question. They provide a pretty detailed look at unit testing for Mac and iPhone.
Brad Larson
I also found my problem by looking at your sample - I had set the target to Device, then the build will succeed, when I set it to Simulator, the STFail, etc will correctly cause the tests to fail !
RRZ Europe
+1  A: 

I demonstrate the setup of unit tests, along with the new UI Automation interface testing instrument, in the video for the "Testing" class session in my iPhone development class on iTunes U. The video for the "Unit testing" session from last semester's class also delves into this in detail.

My course notes for unit testing from last semesters session can be found here. I created a small sample application illustrating the use of unit tests, with the source code available for download from here.

Brad Larson
Thanks for your samples - they are great !
RRZ Europe