Is it possible to run XCTest based tests under Instruments in Xcode 5?

Here's the right way to do it under Xcode 6:

1) In your Xcode project, reveal the "Products" folder, select the ".xctest" product, right-click and finally choose "Reveal in Finder" in the contextual menu.

2) Launch Instruments and create a new document with the template of your choice.

3) Do "Choose Target..." for the document

4) Navigate and select the tool Xcode uses to run tests located at /Applications/Xcode.app/Contents/Developer/usr/bin/xctest (you can find this location using xcrun -f xctest in Terminal) - you will need to enable "Traverse Packages" to navigate inside the Xcode app.

5) Drag & drop from the Finder into the "Arguments" field the ".xctest" product revealed at step 1 - this enters its absolute path.

6) Click "Choose".

You are now ready to run your unit tests from Instruments!

enter image description here


I think this is the easiest way:

  1. Set a breakpoint somewhere in your tests (I've been doing it in the setup method)
  2. Open a new document in instruments
  3. Run the application and make sure it's stopped at a breakpoint
  4. From the Target drop down in Instruments choose Attach to Process and scroll down to your process
  5. Click on record and then resume in XCode

I created a new target based on the mac app target I am testing, then added the xctest classes to the files to compile.

I then added the /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework to the frameworks to link against.

Then added its path $(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks to the Runpath Search Paths.

Then in the main.m I added the following:

    XCTestSuite *suite = [XCTestSuite testSuiteWithName:@"My tests"];
    [suite addTest:[VideohogCachingTest testCaseWithSelector:@selector(testCompleteSequentialText)]];
    [suite run];

This ran the test testCompleteSequentialText on the class VideohogCachingTest I needed to run as a normal application, therefore allowing me to run the test by either command+R or in this case, profiling with command+I. I could then catch a zombie and trace the problem, which was not a possibility for me previously. If you'd like to run all your tests you can do:

XCTestSuite *suite = [XCTestSuite defaultTestSuite];
[suite run];

In Xcode, right click on your test in the test navigator and select "Profile "TestName"":

instruments profile unit test memory