AWS Device Farm生成的.xctestrun格式无效致UI测试失败求助
AWS Device Farm生成的.xctestrun文件格式异常导致iOS UI测试失败问题
问题详情
- AWS Device Farm生成的.xctestrun文件路径存储在环境变量
$DEVICEFARM_XCUITESTRUN_FILE中 - iOS UI测试执行时持续失败,报错信息如下:
xcodebuild: error: Failed to build workspace temporary with scheme Transient Testing. Reason: There are no test bundles available to test. Recovery suggestion: Ensure that all package dependencies have resolved and that there are no missing test bundles in the active scheme or test plan.
- 对比本地Xcode生成的标准.xctestrun文件,发现Device Farm生成的文件存在格式问题:
- 顶层对象仅为本地文件中
TestConfigurations/TestTargets的子对象 - 缺失
TestConfigurations、ContainerInfo等必需的顶层结构 - 不符合
man xcodebuild.xctestrun中定义的文件格式规范
- 顶层对象仅为本地文件中
- 本地使用Device Farm生成的文件运行测试同样失败,但本地Xcode生成的文件可正常执行
可行解决方向
手动修复.xctestrun文件格式
- 以本地Xcode生成的正确文件为模板,将Device Farm生成的
TestTargets内容替换到模板对应位置 - 确保保留
ContainerInfo、TestConfigurations等顶层节点,同时修正测试包路径、依赖引用等字段以适配自定义环境 - 修复完成后,用以下命令验证:
xcodebuild test-without-building -xctestrun <修复后的文件路径>
- 以本地Xcode生成的正确文件为模板,将Device Farm生成的
自定义生成标准.xctestrun文件替代
- 在本地或构建流程中,用Xcode命令行生成符合规范的.xctestrun文件:
xcodebuild build-for-testing -workspace YourWorkspace.xcworkspace -scheme YourScheme -destination 'platform=iOS Simulator,name=iPhone 14' -derivedDataPath ./build - 将生成的标准文件上传到Device Farm自定义环境,或替换
$DEVICEFARM_XCUITESTRUN_FILE指向的文件路径
- 在本地或构建流程中,用Xcode命令行生成符合规范的.xctestrun文件:
排查Device Farm构建配置
- 确认Device Farm中选择的scheme已包含正确的测试目标,且测试目标已开启"Allow testing on external devices"相关配置
- 检查CocoaPods或Swift Package依赖是否存在解析问题,可在构建前添加依赖预安装步骤
关于自定义环境运行的验证
社区中有开发者通过手动修复.xctestrun文件格式的方式,成功在自定义环境中运行测试。核心是补足缺失的顶层结构,并修正路径和配置信息,使其完全符合Xcode官方定义的格式规范。
内容的提问来源于stack exchange,提问作者Sunny
相关产品推荐
相关产品推荐

