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

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

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


Run an individual test

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

-only-testing Pattern

-only-testing:<target>/<class_name>/<test_name>

xcodebuild Pattern

xcodebuild test -workspace "<name>.xcworkspace"  -scheme "<name>" -destination '<options>' -only-testing "<test_case>"

Example

//for example(several test cases)xcodebuild test -workspace "MyApp.xcworkspace"-scheme "MyAppTest" -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.5' -only-testing "MyAppTest/TestClass/foo"-only-testing "MyAppTest/TestClass/foo2"

For example if Test Navigator looks like

the parameter will have the following type

-only-testing:F49088168M_OBDIITests/HexUtilityTests/testHexToBinStringFormat

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 in Derived Data[About]

<derived_data>/<project_name>-dzqvyqfphypgrrdauxiyuhxkfxmg/Logs/Test/Test-<target_name>-<date>.xcresult

[Xcode screenshot]


matomo