有没有办法用 Kiwi 参数化测试?
如果您熟悉 NUnit,它具有运行带参数测试的功能(请参阅http://www.nunit.org/index.php?p=testCase&r=2.5)。
有没有办法用 Kiwi 参数化测试?
如果您熟悉 NUnit,它具有运行带参数测试的功能(请参阅http://www.nunit.org/index.php?p=testCase&r=2.5)。
有一种方法对我有用。
基本上,
在获取参数的测试文件中定义自己的块
typedef void(^TestCount)(INT count);
创建具有相应测试的块
TestCount testCount = ^(INT count){ [[someObject shouldNot] beNil]; [[someObject should] have:count] rows]; };
在需要的地方执行参数化块,我通常在它的块内执行此操作
context(@"when adding object", ^{
beforeAll(^{
[someObject addObject:anotherObject];
});
it(@"it should have 1 object", ^{
testCount(1);
});
});
我希望这有帮助
我最终创建了一个宏来生成 if(..., ^{ });
如果测试失败,这将显示正确的错误消息,但您无法调试:(。
这是它的外观示例:
let(_userModel, ^id{
return [[MyUserModel alloc] init];
});
#define email_should_be_valid(email) \
it(@ #email " should be valid", ^{\
[_userModel setEmail:email];\
[[theValue([_userModel validate:nil]) should] beTrue];\
});
email_should_be_valid(@"example@dd.m")
email_should_be_valid(@"example.example@dd.x")
email_should_be_valid(@"example@dd.com")
#undef email_should_be_valid
我不会将此答案标记为正确,希望有人为此提供更好的解决方案。