Adding Unit Test to Objective C application in XCode 3.2
Adding Unit Test in XCode 3.2.
Some Objective C links:
Learning Objective C
About Unit Tests
Adding Unit Test in XCode 3.2 is very easy, here is a simple note on this:
- Create an objective C application, name it ‘MyApp’, build and run, you see an empty window pops up.
- Right click ‘Targets’, Add/New Target, choose ‘Unit Test Bundle’, set Target name to ‘Unit Tests’
- When Target “unit Tests” info pops up, under ‘General’, ‘Direct Dependencies’, add ‘MyApp’.
- Right click ‘Unit Tests’ under ‘Targets’, build ‘Unit Tests’.
- You see following error, because there is no test yet.
- Add a new group, name it ‘Tests’.
- Right click, add file, choose ‘Objective C test case class’, name it ‘MyTest’, be sure target is: ‘Unit Tests’, uncheck ‘MyApp’ if it is checked. do the step 4 again, passed? if yes, proceed to next step.
- Add a test to MyTest.m
"Command /bin/sh failed with exit code 1"
-(void)testCase1;
{
STAssertEquals(10, 20, @"equal?");
}
build ‘Unit Tests’ again, you will see an error reported:
testCase1] : '10' should be equal to '20': equal?
that means our test is working, set the statement above to:
STAssertEquals(10, 10, @"equal?");
build ‘Unit Tests’ again, passed!
leave a comment