iOS UI 测试失败:IDETestOperations Observer ErrorDomain Code=13

iOS UITests failed: IDETestOperationsObserverErrorDomain Code=13

我是 运行 一个来自 Jenkins 构建脚本的 iOS 应用程序的 AppUITests。单元测试 (AppTests) 运行 正常,但 AppUITests 由于以下问题而失败。我该如何解决这个问题?

09:19:53.506 XCTRunner[22911:77924] Failed to background test runner within 30.0s. 09:19:53.507 xcodebuild[22835:77541] -[IDETestOperationCoordinator testRunnerSession:initializationForUITestingDidFailWithError:] 09:19:53.507 XCTRunner[22911:77924] Calling completion. 09:19:53.507 xcodebuild[22835:77541] Test operation failure: Failed to background test runner. 09:19:53.507 xcodebuild[22835:77541] _finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=13 "Failed to background test runner." UserInfo={NSLocalizedDescription=Failed to background test runner.} didCancel: 1

我在我们的应用程序中遇到了同样的问题。这是由启动时显示的权限警报引起的(在本例中为 APN,但对于任何其他警报可能都是相同的)。

重现步骤

  • 使用将在启动时显示权限提醒的应用程序
  • 确保模拟器干净(以便显示警报)
  • 运行 所有测试

结果

  • 应用启动,显示警报,运行(正常)测试正常
  • 但是 当进入 UITests 时,模拟器将保持黑色,并在片刻之后失败并出现以下错误:

Error Domain=IDETestOperationsObserverErrorDomain Code=13 "Failed to background test runner.

解决方案

运行 正常测试之前的 UITest(只需更改 edit scheme 中的顺序 => Test => Info

备注:

  • 也许您必须确定,UITests 将使用 XTests addUIInterruptionMonitor 方法处理警报。否则,(正常)测试可能会以同样的方式失败(没有测试这种情况)。
  • 如果您真的不想首先 运行 UITest,您可以添加一个额外的 UITest 目标,即 运行 首先,然后只处理警报。然后你应该能够运行(正常)测试,然后是你的 UITests。

相关