如何将 xcodebuild 与 -only-testing 和 -skip-testing 标志一起使用?

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

我注意到 xcodebuild 的手册页中有两个选项。

-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

我的尝试:

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

TEST-IDENTIFIER 是什么意思?

您可以查看视频https://developer.apple.com/videos/play/wwdc2016/409/

我是这样使用的:

-仅测试:UITests/TC_TextArea/test1

我的测试 tree。工作正常

完整命令如下:

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

就像Marcio所说的,它是一个类似string的路径。

例如,假设您有一个名为 MyScheme 的方案,一个测试目标 MyUITests,测试 class LoginTest,然后测试方法 testUserLogin,到 运行只有方法,可以运行

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

同样,如果你想运行所有LoginTest下的测试,这里你运行

xcodebuild -workspace Envoy.xcworkspace \
    -scheme MyScheme \
    -sdk iphonesimulator \
    -destination 'platform=iOS Simulator,name=iPad Air 2,OS=10.1'
    '-only-testing:MyUITests/LoginTest' test
xcodebuild \
 -workspace MyApp.xcworkspace \
 -scheme Automation \
 -destination 'platform=ios,name=My Real iPhone' \
 -only-testing:MyTestDirectory/TestClass/testMethodName \
 test-without-building
  • only-testing不需要单引号
  • 不需要子目录名称,因为它们会被忽略,例如MyTestDirectory/E2E/

要测试应用程序,您需要执行以下两个步骤:

  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>'

这里,<your_test_bundle_to_run>表示TEST-IDENTIFIER,意思是
你要运行有多少个类别或者一个类别下有多少个测试用例,应该包含在测试包下[<your_test_bundle_to_run>]

如果您需要包含多个测试:

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

文档:

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