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.


No comments: