【问题标题】:How to use xcodebuild with -only-testing and -skip-testing flag?如何将 xcodebuild 与 -only-testing 和 -skip-testing 标志一起使用?
【发布时间】:2016-09-10 14:54:59
【问题描述】:

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

-only-testing:TEST-IDENTIFIER       

通过指定要包含的测试和排除其他测试来限制测试

-skip-testing:TEST-IDENTIFIER       

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

我的尝试:

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

TEST-IDENTIFIER 是什么意思?

【问题讨论】:

    标签: xcode xcodebuild


    【解决方案1】:

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

    比如你有一个名为MyScheme的scheme,一个测试目标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
    

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

    【讨论】:

    • 是否可以通过某种方式对此参数使用正则表达式。像 -only-testing:MyUItests/LoginTest[1-2]???
    • 我刚刚更新了这个答案,它部分错误,导致我浪费了大约 30 分钟。在 -only-testing 参数中,您指定目标而不是方案。
    • 更新了答案。而不是'-only-testing:MyUITests/LoginTest/testUserLogin()',它假设是'-only-testing:MyUITests/LoginTest/testUserLogin w/o () 用于测试用例。
    【解决方案2】:

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

    我是这样使用的:

    -only-testing: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'
    

    【讨论】:

    • TEST-IDENTIFIER 是 Xcode 映射测试的方式。检查您的测试树——左侧的第 5 个选项卡。为了工作,你总是必须从根开始,即xcodebuild test skip-testing:MyTestsBundleName/MyClassName/MyTestCaseName
    【解决方案3】:

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

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

    文档:

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

    【讨论】:

    • 找不到对此的参考,您能找到这个吗?干杯!
    • man xcodebuild :)
    【解决方案4】:

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

    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. 在不构建的情况下测试它
        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>'
    

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

    【讨论】:

      【解决方案5】:
      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/

      【讨论】:

        猜你喜欢
        • 2019-02-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-07
        • 1970-01-01
        • 2020-03-22
        • 2021-06-02
        • 2020-09-17
        • 1970-01-01
        相关资源
        最近更新 更多