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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39427263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:13:31  来源:igfitidea点击:

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

xcodexcodebuild

提问by Zigii Wong

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

我注意到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

通过指定要排除的测试来约束测试,但包括其他测试

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-IDENTIFIERmean ?

什么TEST-IDENTIFIER意思?

回答by Fang-Pen Lin

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

就像 Marcio 所说的,它是一个像字符串一样的路径。

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

例如,假设您有一个名为 MyScheme 的方案、一个测试目标MyUITests和测试类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

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

同样,如果您想在 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

回答by N.K.

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

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

I used it like this:

我是这样用的:

-only-testing:UITests/TC_TextArea/test1

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

回答by Vlad

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

xcodebuild 命令可以组合多个约束选项,但 -only-testing: 优先于 -skip-testing:。

回答by user1681739

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/
  • only-testing 不需要单引号
  • 不需要子目录名称,因为它们会被忽略,例如 MyTestDirectory/E2E/

回答by Ali Azam

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

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

  1. build the application
  1. 构建应用程序
    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
  1. 无需构建即可测试
    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-IDENTIFIERthat 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>]

在这里,<your_test_bundle_to_run>表示TEST-IDENTIFIER这意味着
您要运行的类别下有多少个类别或多少个测试用例,应该包含在一个测试包中[ <your_test_bundle_to_run>]