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

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

Check this video: https://developer.apple.com/videos/play/wwdc2016/409/

enter image description here


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).


To run an individual test case you can use -only-testing

xcodebuild test 
-workspace "<name>.xcworkspace"  
-scheme "<name>" 
-destination '<options>' 
-only-testing "<test_case>"
//for example
xcodebuild test 
-workspace "SampleApp.xcworkspace  "
-scheme "SampleAppTest" 
-destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.5' 
-only-testing "SampleAppTest/SampleAppTest/testExample"
-only-testing "SampleAppTest/SampleAppTest/testExample2"
-only-testing:<MyXCTargetForTest>/<MyTestSuite>/<MyTestMethod>
  • MyXCTargetForTest - target
  • MyTestSuite - class_name
  • MyTestMethod - test_name

For example if Test Navigator looks like

enter image description here

the parameter will have the following type

-only-testing:SampleAppTest/SampleAppTest/testExample

If you want to add an additional test case you can add one more -only-testing

Also you can skip a test using: -skip-testing

Test results you can find

/Users/alex/Library/Developer/Xcode/DerivedData/<project_name>-dzqvyqfphypgrrdauxiyuhxkfxmg/Logs/Test/Test-<target_name>-2020.09.25_13-45-46-+0300.xcresult

[Xcode screenshot]

Read more here