iosunit-testingxctestxcode-ui-testing

Running individual XCTest (UI, Unit) test cases for iOS apps from the command line


Is it possible to run individual test cases, or individual test suites, from an iOS app test target, instead of all the test cases, from a command line interface?

You can run tests from command line with xcodebuild, out of the box. When you do so, you run all of the test cases contained in the test target you've selected.

You can also do so with scan from Fastlane, though I believe you're restricted to running all of the tests of the build scheme you select (as above), so it's not different from xcodebuild.

You can run specific tests with xctool from Facebook, but it doesn't use xcodebuild, and is restricted to running on simulators only, not actual iOS test devices.

I found a reference to running the xctest command line utility directly, but it seems to be an undocumented feature and targets DerivedData. This is complicated by the fact that UI Tests, have their *xctest files in a separate XCTRunner bundle.


Solution

  • It is now possible with Xcode 8 using the -only-testing parameter with xcodebuild:

    xcodebuild test -workspace <path>
                    -scheme <name>
                    -destination <specifier>
                    -only-testing:TestBundle/TestSuite/TestCase
    

    enter image description here