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 .
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.
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
I was in similar situation as you and have built a python script that triggers the set of test case/s that i want. Its a little bit elaborate process but works for me and has been very useful over time in implementing DataProvider methods, Rerunning of failed test cases and other customizations I required.
Some relevant steps for what you want to achieve.
If you require more info add a comment I will reply to it.
To run an individual test or test class you can click the diamond next to it in the gutter. This is right next to where line numbers appear if you have them turned on.
In this screenshot my mouse is hovering over the diamond. Notice how it has changed to a little play arrow indicating it will be run.
You can then re-execute the most recently run test(s) with ⌃⌥⌘ G .
As far as I know this cannot be done via the xcodebuild
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.