On Jul 7, 2005, at 5:48 PM, Rush Manbert wrote: I'm hoping that one of the Apple guys will read this and tell me how to use unit tests with the debugger. Since I wrote my test as soon as I finished writing the class under test, I really wanted to use the test code as a way to step through my class code and watch the data while it executed. Is this not possible?
Below is a modified version of what I posted about this in June; it describes what you need to do to debug into a C++ application that uses CPlusTest for its testing framework. The instructions I posted in June are for an Objective-C Cocoa application that uses OCUnit for its testing framework. This all assumes you're creating an application and a test bundle for it, and that you've set your test bundle up properly for testing the application (e.g. that you specified its Test Host and Bundle Loader build settings as described in the Unit Testing Guide).
...
You'll need to set up your application executable in Xcode to support debugging into your tests, by specifying two environment variables. You can do this by highlighting your application in the Executables group of your Xcode project and getting info on it, at the bottom of the inspector you'll see a table view where you can set environment variables and their values.
The environment variables you'll need to specify are DYLD_INSERT_LIBRARIES and XCInjectBundle. You use DYLD_INSERT_LIBRARIES to force a helper library we've supplied to load into your application when it's launched. XCInjectBundle gives that library the path to a bundle of unit tests to load when the helper library itself is loaded. Here's how you should set them:
DYLD_INSERT_LIBRARIES=/System/Library/PrivateFrameworks/DevToolsBundleInjection.framework/DevToolsBundleInjection
XCInjectBundle=$(BUILT_PRODUCTS_DIR)/YourTestBundleName.cptest
Once you do this, you should be able to set breakpoints in your unit tests and then launch your application under the debugger. (Be sure, of course, to use "Debug" rather than "Build & Debug" so you aren't prevented from running under the debugger by unit test failures during build. Since unit tests are run after your built products are created, this will work.)
-- Chris
|