unit-testingxcode4.3sentestingkit

xcode 4.3 unit tests


I'm new to xcode and objective-c. I also decided to add unit (logic) tests to my project. The tests work fine (using OCUnit and SenTestingKit). What I don't understand is how the build for testing works. Let me explain..

I write a simple unit test that checks for an empty array - uses

STAssertTrue([array count] ==0, @"Should have an empty array, but it is not");

This builds fine and the test passes.

Now if I change it from 0 to 1, the build fails. It doesn't make sense to me why the build fails - there is nothing incorrect with the code. It seems to me that the build is actually running the code and the assert is asserting.

How can one step through the code to determine the problem in the method if the method was to return an array with one element? It is obvious in this simple example as to the problem, but if the method to be tested has more depth to it, one needs to step through it to correct the problem. Running unit tests like this does not seem to be very easy to work with - unless there is something I'm completely missing.

My question is: how to step through a unit test that fails?


Solution

  • You need to turn off the Test After Build setting in your project if you don't want broken tests to cause a build failure. If in the future your build is failing because of your tests, you can debug your test cases by executing them (Product -> Test) and setting breakpoints, the same as you would debug any other code. This wasn't always the case with Xcode, but it is with 4.3, as you stated you're using.

    You also ask what "Build for Testing" means. This question covers the same ground: Xcode 4 terms "Build for testing / Build for running / build for profiling / build for archiving"