Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 342
Apophenia Overload Avatar asked Feb 03 '16 00:02

Apophenia Overload


Video Answer


2 Answers

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

like image 147
emoleumassi Avatar answered Sep 23 '22 20:09

emoleumassi


You can edit the scheme to run only specific tests. Select the scheme, then edit scheme. In the appearing window, select the Test phase and disable/enable individual tests.

enter image description here

You can also add schemes to run subsets of tests. When running the tests from command line you can specify the scheme to use for the test (at least in fastlane).

like image 30
dasdom Avatar answered Sep 25 '22 20:09

dasdom