我刚刚开始为我的 iOS 应用程序编写测试,我正在使用 Xcode4 和 OCUnit。我现在正在为一段代码编写一个测试,如果已经分配了静态变量,则该代码应该抛出异常,如下所示:
NSAssert(controllerInstance == nil, @"another controller is already in use!");
在我的测试STAssertThrows
中,如果实例已经存在,我会检查上面的代码是否会引发错误。问题是这个测试失败了:
*** Assertion failure in (reference to row with NSAssert)
因此,即使行为正是我想要的,测试也失败了。但不应该STAssertThrows
抓住这个吗?也许我不应该以这种方式将 NSAssert 与一起使用STAssertThrows
?