【发布时间】:2011-07-18 18:23:50
【问题描述】:
我是第一次使用 Xcode 4 和 GHUnit 编写一些单元测试。所有的建议似乎都建议使用 GHUnit 而不是 OCUnit。
我有一个名为“myList”的自定义集合对象,并传递一条消息以在index:-1 获得选择。因此,它正确地抛出了一个 NSRangeException(来自底层的可变数组)。
我正在努力使用 GHAssertThrowsSpecific 断言来捕捉这一点。
下面这行代码不会编译说“未知类型名称 'NSRangeException”。
GHAssertThrowsSpecific(s = [myList selectionAtIndex:-1],
NSRangeException, @"Should have thrown an NSRangeException", nil);
我是#importing "Foundation/NSException.h",其中似乎定义了 NSRangeException。如果我将其更改为:
GHAssertThrowsSpecific(s = [myList selectionAtIndex:-1],
NSException, @"Should have thrown an NSException", nil);
然后编译正常并且断言有效,所以它与 NSRangeException 有关。
如果我查看标题,NSRangeException 似乎被定义为NSString * const,在这种情况下,我如何尝试断言我期望捕获它。
我显然很愚蠢,因为我看不出我做错了什么。
【问题讨论】:
标签: objective-c unit-testing xcode4 gh-unit