[英]Target individual XCTest unit test cases in Xcode 5 to a specific iOS device for a universal app?
[英]Running individual XCTest (UI, Unit) test cases for iOS apps from the command line
是否可以從命令行界面從 iOS 應用程序測試目標而不是所有測試用例運行單個測試用例或單個測試套件?
您可以使用xcodebuild從命令行運行測試,開箱即用。 當您這樣做時,您將運行您選擇的測試目標中包含的所有測試用例。
您也可以使用 Fastlane 的掃描來執行此操作,但我相信您只能運行 select(如上)的構建方案的所有測試,因此它與 xcodebuild 沒有什么不同。
您可以使用來自 Facebook 的xctool運行特定測試,但它不使用 xcodebuild,並且僅限於在模擬器上運行,而不是在實際的 iOS 測試設備上運行。
我找到了直接運行xctest命令行實用程序的參考,但它似乎是一個未記錄的功能並且以 DerivedData 為目標。 由於 UI 測試將其 *xctest 文件放在單獨的 XCTRunner 包中,這使情況變得復雜。
運行單獨的測試
要運行單個測試用例,您可以使用-only-testing
-only-testing
模式
-only-testing:<target>/<class_name>/<test_name>
xcodebuild
模式
xcodebuild test
-workspace "<name>.xcworkspace"
-scheme "<name>"
-destination '<options>'
-only-testing "<test_case>"
例子
//for example(several test cases)
xcodebuild test
-workspace "MyApp.xcworkspace"
-scheme "MyAppTest"
-destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.5'
-only-testing "MyAppTest/TestClass/foo"
-only-testing "MyAppTest/TestClass/foo2"
例如,如果Test Navigator
看起來像
參數將具有以下類型
-only-testing:F49088168M_OBDIITests/HexUtilityTests/testHexToBinStringFormat
如果你想添加一個額外的測試用例,你可以再添加一個-only-testing
您也可以使用以下-skip-testing
跳過測試: -skip-testing
您可以在Derived Data
找到測試結果[關於]
<derived_data>/<project_name>-dzqvyqfphypgrrdauxiyuhxkfxmg/Logs/Test/Test-<target_name>-<date>.xcresult
我和你的情況類似,並且已經構建了一個 python 腳本來觸發我想要的一組測試用例。 它的過程有點復雜,但對我有用,並且隨着時間的推移在實現 DataProvider 方法、重新運行失敗的測試用例和我需要的其他自定義方面非常有用。
您想要實現的一些相關步驟。
如果您需要更多信息,請添加評論,我會回復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.