ios - 在 Kiwi 测试期间获得 BAD_EXCESS,

标签 ios objective-c testing bdd kiwi

我正在研究用于测试的 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/

相关文章:

ios - 我的自定义 UIView 未从 SuperView 中删除

ios - 照片的JPEG NSData转UIImage转JPEG大小完全不同

django - 使用 Django Rest Framework 测试 CSRF 验证

ios - 数组中的 Swift 通用协议(protocol)类类型

ios - 创建三角形 ios swift View

ios - AirPlay 没有出现在 iOS 10 中

ios - Nimbus 与使用 cocoapods 的 iOS 4.3 不兼容

ios - 如何在 OpenAL 中停止声音 Smooth

java - Mockito 模拟 restTemplate.postForEntity

python - 我如何测试使用 input() 的初学者 Python 程序(也许使用 unittest?)?