我正在研究用于测试的 kiwi 框架
myStack.m
- (id) init {
if (self = [super init]) {
_data = [[NSMutableArray alloc] initWithCapacity:4];
}
return self;
}
- (void) push:(int)numberToPush {
[self.data addObject:numberToPush];
}
- (int)top {
return [[self.data lastObject] integerValue];
}
-(int)numberOfItem {
return [self.data count];
}
测试是
SPEC_BEGIN(MyStack)
describe(@"The stack", ^{
__block MyStack *stack;
context(@"when created", ^{
beforeAll(^{
stack = [[MyStack alloc] init];
});
it(@"is not nil.", ^{
[stack shouldNotBeNil];
});
it(@"allows me to count the item of stack", ^{
[stack push:5];
[[stack should] haveCountOf:1];
});
});
});
SPEC_END
但是,我在 Expectations
测试中遇到了 BAD_EXCESS。我不知道为什么会出现此错误。欢迎所有帮助。
最佳答案
看起来您正在尝试将 int
添加到您的 NSMutableArray
。您只能将对象添加到 NSArray
,而不能添加基本类型。在 push:
的实现中尝试在 NSNumber
中装箱:
- (void) push:(int)numberToPush {
[self.data addObject:@(numberToPush)];
}
关于ios - 在 Kiwi 测试期间获得 BAD_EXCESS,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18222706/