[英]Running individual XCTest (UI, Unit) test cases for iOS apps from the command line
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?是否可以从命令行界面从 iOS 应用程序测试目标而不是所有测试用例运行单个测试用例或单个测试套件?
You can run tests from command line with xcodebuild , out of the box.您可以使用xcodebuild从命令行运行测试,开箱即用。 When you do so, you run all of the test cases contained in the test target you've selected.
当您这样做时,您将运行您选择的测试目标中包含的所有测试用例。
You can also do so with scan from Fastlane, though I believe you're restricted to running all of the tests of the build scheme you select (as above), so it's not different from xcodebuild.您也可以使用 Fastlane 的扫描来执行此操作,但我相信您只能运行 select(如上)的构建方案的所有测试,因此它与 xcodebuild 没有什么不同。
You can run specific tests with xctool from Facebook, but it doesn't use xcodebuild, and is restricted to running on simulators only, not actual iOS test devices.您可以使用来自 Facebook 的xctool运行特定测试,但它不使用 xcodebuild,并且仅限于在模拟器上运行,而不是在实际的 iOS 测试设备上运行。
I found a reference to running the xctest command line utility directly, but it seems to be an undocumented feature and targets DerivedData.我找到了直接运行xctest命令行实用程序的参考,但它似乎是一个未记录的功能并且以 DerivedData 为目标。 This is complicated by the fact that UI Tests, have their *xctest files in a separate XCTRunner bundle .
由于 UI 测试将其 *xctest 文件放在单独的 XCTRunner 包中,这使情况变得复杂。
You can edit the scheme to run only specific tests.您可以编辑方案以仅运行特定测试。 Select the scheme, then edit scheme.
选择方案,然后编辑方案。 In the appearing window, select the Test phase and disable/enable individual tests.
在出现的窗口中,选择测试阶段并禁用/启用单个测试。
You can also add schemes to run subsets of tests.您还可以添加方案来运行测试的子集。 When running the tests from command line you can specify the scheme to use for the test (at least in fastlane).
从命令行运行测试时,您可以指定用于测试的方案(至少在 fastlane 中)。
Run an individual test运行单独的测试
To run an individual test case you can use -only-testing
要运行单个测试用例,您可以使用
-only-testing
-only-testing
Pattern -only-testing
模式
-only-testing:<target>/<class_name>/<test_name>
xcodebuild
Pattern xcodebuild
模式
xcodebuild test
-workspace "<name>.xcworkspace"
-scheme "<name>"
-destination '<options>'
-only-testing "<test_case>"
Example例子
//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"
For example if Test Navigator
looks like例如,如果
Test Navigator
看起来像
the parameter will have the following type参数将具有以下类型
-only-testing:F49088168M_OBDIITests/HexUtilityTests/testHexToBinStringFormat
If you want to add an additional test case you can add one more -only-testing
如果你想添加一个额外的测试用例,你可以再添加一个
-only-testing
Also you can skip a test using: -skip-testing
您也可以使用以下
-skip-testing
跳过测试: -skip-testing
Test results you can find in Derived Data
[About]您可以在
Derived Data
找到测试结果[关于]
<derived_data>/<project_name>-dzqvyqfphypgrrdauxiyuhxkfxmg/Logs/Test/Test-<target_name>-<date>.xcresult
I was in similar situation as you and have built a python script that triggers the set of test case/s that i want.我和你的情况类似,并且已经构建了一个 python 脚本来触发我想要的一组测试用例。 Its a little bit elaborate process but works for me and has been very useful over time in implementing DataProvider methods, Rerunning of failed test cases and other customizations I required.
它的过程有点复杂,但对我有用,并且随着时间的推移在实现 DataProvider 方法、重新运行失败的测试用例和我需要的其他自定义方面非常有用。
Some relevant steps for what you want to achieve.您想要实现的一些相关步骤。
If you require more info add a comment I will reply to it.如果您需要更多信息,请添加评论,我会回复。
To run an individual test or test class you can click the diamond next to it in the gutter.要运行单个测试或测试类,您可以单击装订线中它旁边的菱形。 This is right next to where line numbers appear if you have them turned on.
如果您打开它们,它就在行号出现的位置旁边。
In this screenshot my mouse is hovering over the diamond.在此屏幕截图中,我的鼠标悬停在钻石上方。 Notice how it has changed to a little play arrow indicating it will be run.
注意它是如何变成一个小播放箭头的,表示它将被运行。
You can then re-execute the most recently run test(s) with ⌃⌥⌘ G .然后,您可以使用⌃⌥⌘ G重新执行最近运行的测试。
As far as I know this cannot be done via the xcodebuild
.据我所知,这不能通过
xcodebuild
完成。
May be this helps.可能这有帮助。 I was ignorant because I didn't know that you can disable some particular tests in Test navigator by right-clicking them.
我很无知,因为我不知道您可以通过右键单击测试导航器中的某些特定测试来禁用它们。
Then you run xcodebuild test -scheme <name>
as usual, and all the disabled tests will be ignored.然后像往常一样运行
xcodebuild test -scheme <name>
,所有禁用的测试都将被忽略。 Worked with Fastlane for me.为我与 Fastlane 合作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.