如何用XcodeGen引用TestPlans?多测试目标与Scheme适配问题
XcodeGen 结合 TestPlans 配置解决方案
核心问题是未在 Scheme 配置中开启 TestPlan 模式,仅指定路径无法生效。正确配置需覆盖三个关键项:开启 TestPlan 模式、指定 TestPlan 文件路径、关联对应测试目标。
可行的 Scheme 模板配置示例:
schemeTemplates: MyAppSchemeTemplate: build: targets: MyApp: [run, test] test: # 必须添加此配置,开启 Scheme 的 TestPlan 模式 useTestPlans: true testPlans: - path: Tests/UnitTestsFeatureAOnlyTestPlan.xctestplan # 绑定该 TestPlan 对应的所有测试目标 targets: - MyAppUnitTests - MyAppUITests # 删除原有的 testTargets 配置,两者互斥会导致 TestPlan 模式失效
- 多 Scheme 多 TestPlan 场景扩展配置:
若需为不同 Scheme 绑定不同 TestPlan,无需修改模板,直接在 project 的 schemes 节点单独配置即可:
schemes: MyApp-FeatureA: template: MyAppSchemeTemplate test: testPlans: - path: Tests/UnitTestsFeatureAOnlyTestPlan.xctestplan targets: [MyAppUnitTests-FeatureA] MyApp-FullTest: template: MyAppSchemeTemplate test: testPlans: - path: Tests/FullUnitTestPlan.xctestplan targets: [MyAppUnitTests, MyAppUITests, MyAppIntegrationTests]
- 验证配置有效性:
生成项目后打开自动生成的project.xcscheme,检查<TestAction>节点下是否存在<TestPlans>结构,且包含你的 TestPlan 文件路径与绑定的测试目标。确认结构正确后,执行带-testPlan参数的xcodebuild命令即可正常运行。
内容的提问来源于stack exchange,提问作者Bruno Cunha
相关产品推荐
相关产品推荐

