18

I found a command-line tool called "xctest" that apparently can run the unit tests in your project. This executable lives here:

/Applications/Xcode.app/Contents/Developer/usr/bin/xctest

When I try to run this executable on my xctest bundle, I'm using:

$ ./xctest /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

However, I get the following output:

Test Suite '(null)' started at 2013-11-14 21:16:45 +0000
Test Suite '(null)' finished at 2013-11-14 21:16:45 +0000.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

There's no man page for xctest, as far as I can tell, but entering just ./xctest at the command-line yields:

Usage: xctest [--test Self | All | None | <TestCaseClassName/testMethodName>] <path of unit to be tested>

In particular, I'd like to be able to test just a particular method in a test class, which is why I'd like to use this xctest command.

I do see that there is a way to run all the tests from the command line like:

$ xcodebuild test -scheme MyApp

This runs all the unit tests and works properly (I see my unit test results, unlike when using xctest). But I'm interested in being able to run a single test method from the command-line, such as:

$ ./xctest --test MyAppTests/testExample  /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

1 Answer 1

8

Despite what the usage message says -XCTest is the argument you need:

xctest -XCTest MyAppTests/testExample testbundle.xctest

For a direct invocation of xctest to work you may also need to set DYLD_FRAMEWORK_PATH and DYLD_LIBRARY_PATH to your built products directory. In general you need to use the same arguments and environment as Xcode does, you can see this by putting a breakpoint in one of your tests, running them through Xcode, then printing out the values of arguments and environment for [NSProcessInfo processInfo].

To avoid messing with all that note you can also modify the scheme in Xcode to run only specific tests. Under Product > Scheme > Edit Scheme select the Test action and expand the test bundle. You can use the check boxes to select the tests to run and xcodebuild's test action will then run only these tests.

2
  • 1
    Thanks! I actually did not need to set the environment variables for DYLD_FRAMEWORK_PATH and DYLD_LIBRARY_PATH. I needed to make sure I had the correct xctest bundle location in Build/Products/Testing, instead of Build/Products/Debug. So my path was like: ./xctest -XCTest MyTestClass/testMyTestFunction /Users/username/Library/Developer/Xcode/DerivedData/MyApp-abcdefghikjklmn/Build/Products/Testing/MyAppTests.xctest Apr 15, 2014 at 20:40
  • Thanks for the tip about disabling tests in the scheme. You can select multiple rows and use spacebar to toggle selection--very useful!
    – funroll
    May 19, 2014 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.