Sunday, October 18, 2009

Debugging Individual CPlusTestRig Test Cases

Having got the unit tests working in the debugger I don't really want all the tests to be executed each time I run the debugger. I just want to work with the problem test.

The easiest method I know of is just linking in the tests that you want. It is what I have used in the past when fixing unit tests (prior to getting the debugger to work I used NSLog calls and just looked at the output - my programming start predates symbolic debuggers and if you go old school you can still find bugs and fix things).

I have named all my tests files so that they end in _test and then the file suffix. This means that I can: 


  1. Select all my test files in the search widget in XCode by typing _test.cpp and then in the main area choose the tests that I do not want
  2. Click on the Info button in the tool bar to get info on all of the tests
  3. Select the Targets pain in the info window and turn off the tests that I don't want to run.


As I have boith .cpp and .mm files this is actually a two stage process - but it is very simple to do.

Wednesday, October 14, 2009

Debugging CPlusTestRig UnitTests

Having started work on the user interface I am doing a fair bit of reorganizing. In this reorganization I have been changing the way that UI related components are being registered. What has happened is that in the early stages of development I had roughed-out stubs installed as the needed UI components - but these no longer load. The upshot of this is that I have made the first progress am ready to commit my changes to the library but my unit tests are failing - components are missing. I am getting crashes.

Pinning down these sort of problem with a debugger is generally quite straight forward. My frustration is that out of the tin the debugger does not "just work". OSX has made me lazy - I am used to things just working.

The best set of hints I have found on this are on Chris Hanson's blog - this is for testing cocoa frameworks. I am using CPlusTestRig but there is enough there to figure out what you need to do. This is my recipe


Turn off the automatic running of unit tests.


I did this as I wanted my unit test related files to build but I did not want the shell scripts that executes them to run. If it does run it will run outside of the debugger. To do this:
  • Selected the Unit Test target in the files
  • Choose get info from the tool bar
  • Put a hash (#) in front of the line "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" this has the effect of commenting it out. If you do it this way you can remove the hash character and be back where you were.

Create a new Executable 


  • Choose Project>New Custom Executable
  • Give it a name (I choose "Debug UnitTests") and enter "Tools/CPlusTestRig" in the Executable path
  • In the window that appears click on the Arguments Tab and add in the name of your test bundle - if you have spaces in your name you need to escape them

Run


  • Set your active executable.
  • Hit the debug button on your toolbar.