How to use xcodebuild with -only-testing and -skip-testing flag?

Zigii Wong picture Zigii Wong · Sep 10, 2016 · Viewed 11.5k times · Source

I've noticed that there are two options in xcodebuild's man page.

-only-testing:TEST-IDENTIFIER       

constrains testing by specifying tests to include, and excluding other tests

-skip-testing:TEST-IDENTIFIER       

constrains testing by specifying tests to exclude, but including other tests

What I try:

xcodebuild -workspace MyWorkSpace.xcworkspace / 
-sdk iphonesimulator / 
-destination id=7F52F302-C6AF-4215-B269-39A6F9913D5B / 
-scheme SCHEME-iOS / 
test -only-testing:???

What is TEST-IDENTIFIER mean ?

Answer

Fang-Pen Lin picture Fang-Pen Lin · Nov 12, 2016

Like what Marcio said, it's a path like string.

For example, say you have a scheme named MyScheme, a test target MyUITests, and testing class LoginTest, then testing method testUserLogin, to run only the method, you can run

xcodebuild -workspace Envoy.xcworkspace \
    -scheme MyScheme \
    -sdk iphonesimulator \
    -destination 'platform=iOS Simulator,name=iPad Air 2,OS=10.1'
    '-only-testing:MyUITests/LoginTest/testUserLogin' test

Likewise, if you want to run all tests under LoginTest, here you run

xcodebuild -workspace Envoy.xcworkspace \
    -scheme MyScheme \
    -sdk iphonesimulator \
    -destination 'platform=iOS Simulator,name=iPad Air 2,OS=10.1'
    '-only-testing:MyUITests/LoginTest' test