Rus*_*anD 12 xcode ios xctest xcode9-beta xcode9
我在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 objc_exception_throw + 48
2 CoreFoundation 0x0000000102562362 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000101827089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 XCTest 0x0000000101d96875 -[XCTestCase recordFailureWithDescription:inFile:atLine:expected:] + 518
5 MyAppUnitTests 0x000000011d7f2f5a -[HCXCTestFailureReporter executeHandlingOfFailure:] + 154
6 MyAppUnitTests 0x000000011d7f2b73 -[HCTestFailureReporter handleFailure:] + 67
7 MyAppUnitTests 0x000000011d64ec9a MKTFailTest + 217
8 MyAppUnitTests 0x000000011d64c3f4 -[MKTExactTimes verifyData:] + 254
9 MyAppUnitTests 0x000000011d64f2ba -[MKTBaseMockObject verifyInvocation:usingVerificationMode:] + 137
10 MyAppUnitTests 0x000000011d64f20b -[MKTBaseMockObject handlingVerifyOfInvocation:] + 115
11 MyAppUnitTests 0x000000011d64f15a -[MKTBaseMockObject forwardInvocation:] + 64
12 CoreFoundation 0x00000001024dfed8 ___forwarding___ + 760
13 CoreFoundation 0x00000001024dfb58 _CF_forwarding_prep_0 + 120
14 MyAppUnitTests 0x000000011c40b486 -[FooTest setUp] + 294
15 XCTest 0x0000000101d97b39 __24-[XCTestCase invokeTest]_block_invoke_3 + 31
16 XCTest 0x0000000101d97809 __24-[XCTestCase invokeTest]_block_invoke + 271
17 XCTest 0x0000000101ddff45 -[XCUITestContext performInScope:] + 183
18 XCTest 0x0000000101d976ef -[XCTestCase invokeTest] + 141
注意事项:
[verify(_mockTestObject) description];
事实上,所有因此异常而失败的单元测试都会失败,因为我们正在尝试验证-[NSObject description]是否已在一个模拟对象或另一个模拟对象上调用.删除验证该调用的所有实例都会使测试通过.
我在Google上搜索了这个特定NSInternalInconsistencyException的其他实例,但没有产生任何结果.我不确定以什么方式 - [NSObject描述]与可能在模拟对象上调用的任何其他方法不同 - 问题可能不存在,但它只是表现出来.我还试图找到是否有任何调试/诊断选项我可以打开XCTest所以我可能会获得更多关于测试执行的详细日志信息,但我也没有找到类似的东西.
关于我接下来应该去哪看的任何想法?非常感谢!
我在进行一些大型遗留代码测试时遇到了类似的问题。问题是:XCTExpectation当你单独运行它们时,你的测试工作正常吗?如果是这样,这意味着在测试之前执行的某些测试正在以在相关测试完成后执行它们的方式NSInternalInconsistencyException分派相关方法。XCTest
它看起来像(示例):
Test1 -> 异步分派执行的“块”XCTFail
测试1 -> 完成
XCTFail在主线程或其他线程上执行(但 Test1 通过,因为它完成时没有“失败”)。
Test2 -> 测试一些东西XCTExpectation->NSInternalInconsistencyException
Apple 文档没有提供有关 XCTest 内部结构的太多信息,但我很确定这就是问题所在。尝试按照以下故障排除步骤来确定测试“冲突”(那些在没有 XCTestExpectation 的情况下执行异步操作的不良测试,例如使用带有完成处理程序的方法,这些方法最终会执行XCTest断言、失败等):
FooTest.就我而言,有多个测试导致了与 的冲突XCTestExpectation,因此搜索非常麻烦(一套 1000+ 的测试需要几个小时XCTestCases,所以大约 5k 次测试)。
然后彻底调查测试中发生的与您的测试相冲突的情况。
| 归档时间: |
|
| 查看次数: |
1587 次 |
| 最近记录: |