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

喜夏-厌秋 提交于 2019-11-29 21:34:14

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

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

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!

Pellet

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!