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

送分小仙女□ 提交于 2019-11-29 17:19:29

问题


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 ?


回答1:


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



回答2:


You can check the video https://developer.apple.com/videos/play/wwdc2016/409/

I used it like this:

-only-testing:UITests/TC_TextArea/test1

for my tests tree. Works fine

Full command looks as follows:

command = 'xcodebuild test 
-workspace ' + pathToProjectWorkspaceFolder + '/project.xcworkspace 
-scheme yourApp.app 
-destination "platform=iOS,name=' + deviceName + '" 
-only-testing:UITests/TC_TextArea/test1'



回答3:


In case you need to include several tests:

xcodebuild -project Some.xcodeproj \
-scheme AllTests -only-testing:PersistenceTests -only-testing:FoundationTests test

Documentation:

An xcodebuild command can combine multiple constraint options, but -only-testing: has precedence over -skip-testing:.




回答4:


xcodebuild \
 -workspace MyApp.xcworkspace \
 -scheme Automation \
 -destination 'plaform=ios,name=My Real iPhone' \
 -only-testing:MyTestDirectory/TestClass/testMethodName \
 test-without-building
  • No need for single quotation marks around only-testing
  • No need for the sub-directory names as they are ignored e.g. MyTestDirectory/E2E/



回答5:


To test an application you need to go with the two steps:

  1. build the application
    xcodebuild build-for-testing \
        -workspace "<your_xcworkspace>" \
        -scheme "<your_scheme>" \
        -destination "platform=iOS Simulator,name=<your_simulator>,OS=<simdevice_os_version>" \
        -derivedDataPath "All"
  1. test it without building
    xcodebuild test-without-building \
        -xctestrun "All/Build/Products/<your_scheme>_iphonesimulator<simdevice_os_version>-x86_64.xctestrun" \
        -destination "platform=iOS Simulator,name=<your_simulator>,OS=<simdevice_os_version>" '-only-testing:<your_test_bundle_to_run>'  \
        -derivedDataPath 'build/reports/<your_test_bundle_to_run>'

Here, <your_test_bundle_to_run> indicates the TEST-IDENTIFIER that means
How many categories or how many test cases under a category you want to run, that should be included under a test bundle[<your_test_bundle_to_run>]



来源:https://stackoverflow.com/questions/39427263/how-to-use-xcodebuild-with-only-testing-and-skip-testing-flag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!