Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4, breakpoints not working in unit tests for Mac OS command line tool

I have a simple Mac OS X Command Line Tool project in Xcode 4.5. I manually added a unit test target off of the Cocoa Unit Testing Bundle template (the Command Line Tool template doesn't have an Include Unit Tests switch). The problem: I can't get the debugger to stop on a breakpoint when running tests (Product > Test).

As I did a google search before asking, these are some things I already tried/checked:

  • The unit tests do run (they correctly fail on e.g. STFail()).
  • The master Breakpoints switch on the top bar is on (turning it off and on doesn't help).
  • Build Configuration is set to Debug on the test target (debugger is LLDB, changing to GDB doesn't help).
  • Debugging in general works. In the main console app target breakpoints are hit just fine so it's just the unit tests that have a problem. Also, I made a test iOS app with unit tests included -- both the app and unit tests break fine.
  • The build settings look fine (let me know if there are other I ought to check):
    • Generate Debug Symbols = Yes
    • Optimization Level = None [-O0] (for Debug)
  • Setting a symbolic breakpoint (on -[NSException raise] or objc_exception_throw) doesn't help.
  • Reloading project or restarting Xcode doesn't help.

What else can I do to hit a breakpoint in my unit tests?

like image 875
Tomek Sowiński Avatar asked Mar 01 '26 22:03

Tomek Sowiński


1 Answers

Check your "Test after build" build setting (under "Unit Testing") for your unit testing target.

If this setting is set to "Yes" then after your target is built the tests will be executed through a shell script "outside" of Xcode before being executed (again) via Xcode. So if your tests are failing when the script is being executed then the second execution ("inside" Xcode) will not occur and so your breakpoints will not be hit.

-or-

If the test you are trying to debug is a failing test, it's possible that failure is occurring in your -setUp method. This might happen if you are using OCMock in your setUp and you have forgotten to stub a method that happens to be called during the setup.

like image 160
mamills Avatar answered Mar 04 '26 12:03

mamills