考虑这个示例项目:https://github.com/stremsdoerfer/TestPlan。这只是一个Hello World,它有两个测试计划:TestPlanUnit
只运行单元测试,TestPlanUI
只运行UI测试。
使用Xcode 14.3运行下面的命令,我希望运行TestPlanUI
,但只有TestPlanUnit
运行,这是默认的。
xcodebuild -scheme TestPlan -destination 'platform=iOS Simulator,id=<sim_id>' -testPlan TestPlanUI test-without-building
它可以在Xcode 14.2中正常工作。使用test
代替test-without-building
也可以。
任何想法吗?
有同样的问题,并向苹果报告了一个问题。当传递test-without-building
时,testPlan
参数似乎被忽略了。
我也向苹果报告了testPlan ignored when using xcodebuild test-without-building
。苹果回复:Potential fix identified - For a future OS update
.
这不是一个解决方案,而是一个潜在的变通方法,直到苹果公司修复它。如果您创建了Scheme的副本,然后将该Scheme的默认TestPlan设置为您想要运行的测试,则test-without-building将关注Scheme中的默认测试。
我已经测试了fastlane
和直接使用xcodebuild
,两者都是这样工作的。我不喜欢它,尤其是因为我的方案相当复杂。但是,我确实成功地运行了测试。
确保您的运行变体都已构建。我遇到了一个问题,我复制了我的方案一段时间后,一个方案由运行发散诊断/对于单个TestPlan的运行时清理的设置。因此,当我在关闭清理的情况下在CI中运行测试时,该方案需要Variant-NoSanitizers
中的二进制文件。
实际上我得到了一个不需要任何hack的工作解决方案🔥
第一次调用xcodebuild
将创建一个xctestrun
文件:
xcrun xcodebuild build-for-testing -workspace <project_root>/<project_name>.xcworkspace -scheme <scheme> -destination 'platform=iOS Simulator,id=2253C0D7-C198-44AD-A98B-11301FD88F30'
该文件将位于DerivedData文件夹中,并命名为:
~/Library/Developer/Xcode/DerivedData/<build_folder>/Build/Products/<scheme>_<test_plan_name>_<device_type><ios-version>-<architecture>.xctestrun
例如MyScheme_Screenshots_iphonesimulator16.4-arm64.xctestrun
xcodebuild
的第二次调用然后使用该文件运行测试。当使用-xctestrun
:
[-project, -scheme, -workspace]
。xcrun xcodebuild test-without-building -destination 'platform=iOS Simulator,id=2253C0D7-C198-44AD-A98B-11301FD88F30' -xctestrun ~/Library/Developer/Xcode/DerivedData/<build_folder>/Build/Products/<scheme>_<test_plan_name>_<device_type><ios-version>-<architecture>.xctestrun
希望对大家有所帮助👍
PS:在这里,你可以找到我的命令行工具Snap
的Pull Request,它集成了这个修复。Snap使用Xcode TestPlans创建截图。超级有用的CI🔥