_XCTFailInCurrentTest 只应在测试 运行 时调用

_XCTFailInCurrentTest should only be called while a test is running

我现在正在使用 Xcode 进行 UITesting,但我遇到了这个错误。

* Assertion failure in void _XCTFailInCurrentTest(NSString *, ...)(), /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63 2016-05-13 22:31:54.961 XCTRunner[15428:168507] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_XCTFailInCurrentTest should only be called while a test is running. Failure description: Failed to receive completion for

我在这里看到了其他类似的post。

Cannot run Xcode (7.3) UI tests in Jenkins

我正在使用 Jenkins,但现在,我直接从 Xcode 运行 宁,我什至不能从 Xcode 运行。我该怎么办?

背景

  • 我在 Xcode 7.3 (7D175) 和 iOS Simulator 9.3 中遇到过这个问题。
  • 症状如下
    • Test Runner 正常启动并退出。
    • 在此之后,被测应用程序从未启动。
    • (如果未安装被测应用,Xcode 也不会在开始测试之前安装该应用)。
    • (副作用是录音对我也不起作用 - 我从
    • 中获得灵感

30 秒后测试超时:

XCTRunner[36260:489138] Continuing to run tests in the background with task ID 1    
2016-05-18 16:17:25.720 XCTRunner[36260:489138] *** Assertion failure in void _XCTFailInCurrentTest(NSString *, ...)(), /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-10112/XCTestFramework/Classes/XCTestCase.m:63
2016-05-18 16:17:25.723 XCTRunner[36260:489138] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_XCTFailInCurrentTest should only be called while a test is running.
Failure description: Failed to receive completion for <XCDeviceEvent:0x7fddc241f970 page 12 usage 64 duration 0.01s within 30.0s'

对我有用的修复是:

  • 重置模拟器。
  • 检查 UI 测试目标的构建设置中的部署目标是否设置为 iOS 9.x。 (在我的例子中它被设置为 iOS 8)
  • 更改目标后,清理并重建。

完成这些步骤后,Xcode 能够在测试前安装应用程序,录制成功,错误消失。

由于某种原因,模拟器已损坏。在我的例子中,一旦到达同一点就不可能启动任何测试。在我的例子中,它起作用的是重置模拟器(菜单模拟器|重置内容和设置...)或切换到任何其他模拟器。

我们尝试了其他回复中的提示,但对我们不起作用。
完全重新安装 Xcode 7.3 解决了我们的问题。

  • 移除Xcode
  • 重启
  • 重新安装Xcode
  • 成功