Strictly Programming

Adding Unit Test to Objective C application in XCode 3.2

Posted in Objective-C, Uncategorized by sqllyw on 11/22/2009

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:

  1. Create an objective C application, name it ‘MyApp’, build and run, you see an empty window pops up.
  2. Right click ‘Targets’, Add/New Target, choose ‘Unit Test Bundle’, set Target name to ‘Unit Tests’
  3. When Target “unit Tests” info pops up, under ‘General’, ‘Direct Dependencies’, add ‘MyApp’.
  4. Right click ‘Unit Tests’ under ‘Targets’, build ‘Unit Tests’.
  5. You see following error, because there is no test yet.
  6. "Command /bin/sh failed with exit code 1"
    
  7. Add a new group, name it ‘Tests’.
  8. 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.
  9. Add a test to MyTest.m
  10. -(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!

Advertisements
Tagged with: ,

One Response

Subscribe to comments with RSS.

  1. Vijay Radke said, on 09/21/2011 at 1:40 pm

    I did all the steps as you describe but I got the error : “Command /bin/sh failed with exit code 1” Any solution for this.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: