Running individual XCTest (UI, Unit) test cases for iOS apps from the command line

后端 未结 5 1664
后悔当初
后悔当初 2020-12-02 20:44

Is it possible to run individual test cases, or individual test suites, from an iOS app test target, instead of all the test cases, from a command line interface?

Yo

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 21:07

    To run an individual test case you can use -only-testing

    xcodebuild test 
    -workspace .xcworkspace  
    -scheme "" 
    -destination '' 
    -only-testing 
    
    //for example
    xcodebuild test 
    -workspace SampleApp.xcworkspace  
    -scheme "SampleAppTest" 
    -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.5' 
    -only-testing SampleAppTest/SampleAppTest/testExample
    -only-testing SampleAppTest/SampleAppTest/testExample2
    
    -only-testing://
    
    • MyXCTargetForTest - target
    • MyTestSuite - class_name
    • MyTestMethod - test_name

    For example if Test Navigator looks like

    the parameter will have the following type

    -only-testing:SampleAppTest/SampleAppTest/testExample
    

    If you want to add an additional test case you can add one more -only-testing

    Also you can skip a test using: -skip-testing

    Test results you can find

    /Users/alex/Library/Developer/Xcode/DerivedData/-dzqvyqfphypgrrdauxiyuhxkfxmg/Logs/Test/Test--2020.09.25_13-45-46-+0300.xcresult
    

    [Xcode screenshot]

    Read more here

提交回复
热议问题