Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Debugging a unit test target

I am writing tests for my iPhone app using OCUnit. Is there any way to debug the unit tests and have a break point to see what the heck is happening?

It's ridiculously hard to write unit tests without being able to use breakpoints.

like image 362
aryaxt Avatar asked Apr 06 '11 23:04

aryaxt


People also ask

Can you debug a unit test?

Debug and analyze unit tests with Test Explorer You can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test.


3 Answers

Using XCode 4.2, (with SenTestKit unit tests as set up by checking the "Include Unit Tests" checkbox when setting up the project), Product->Test wasn't hitting my breakpoints, but Product->Perform Action->Test Without Building seems to do the trick. Hope this helps.

like image 54
Daniel Sproul Avatar answered Oct 19 '22 10:10

Daniel Sproul


The link posted by David Gelhar is correct for Xcode 3.

For Xcode 4, things are much simpler. Edit your current scheme and go to the "Test" action. Click the '+' at the bottom and add the test bundle that contains the tests you want to run. Now when you choose Product -> Test, it will run those tests. Any active breakpoints will be hit just like you'd expect.

like image 44
BJ Homer Avatar answered Oct 19 '22 10:10

BJ Homer


Here's a blog post: Debugging Cocoa application unit tests with instructions for how to do this (for XCode 3 at least; not sure about XCode 4).

like image 1
David Gelhar Avatar answered Oct 19 '22 10:10

David Gelhar