我在Xcode 9 GM上运行我的iOS应用程序的单元测试,其中一些是因为奇怪的NSInternalInconsistencyException而失败,抱怨无法报告某些测试断言,因为所涉及的测试没有关联的XCTestRun对象.我正在使用OCMockito + OCHamcrest进行模拟和呼叫验证.
出于演示目的,假设我的应用程序名为MyTestApp,我有一个测试类FooTest(继承自XCTestCase).在-setUp中,我为测试创建并连接各种模拟对象,而在-tearDown中我将它们设置为nil以防万一.
这是我得到的例外情况的一个例子:
2017-09-19 13:23:01.852729-0700 xctest[17006:5392130] *** Assertion failure in -[FooTest recordFailureWithDescription:inFile:atLine:expected:], /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-13201/Sources/XCTestFramework/Core/XCTestCase.m:308
/Users/fooUser/Workspaces/MyTestApp/tests/FooTest.mm:46: error: -[FooTest testSomething] : failed: caught "NSInternalInconsistencyException", "Unable to report test assertion failure 'Expected 1 matching invocation, but received 0' from /Users/fooUser/Workspaces/MyTestApp/tests/FooTest.mm:135 because it was raised inside test case -[FooTest testSomethingElse] which has no associated XCTestRun object. This may happen when test cases are constructed and invoked independently of standard XCTest infrastructure."
(
0 CoreFoundation 0x000000010255d1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000101ebff41 …