Reputation: 1263
Is there a way to parameterize test with Kiwi ?
If you are familiar with NUnit, it has a feature of running a test with parameters ( see http://www.nunit.org/index.php?p=testCase&r=2.5 ).
Upvotes: 1
Views: 124
Reputation: 647
There's one way that works for me.
Basically,
Define your own block in test file that gets your parameter(s)
typedef void(^TestCount)(INT count);
Create the block with corresponding tests
TestCount testCount = ^(INT count){ [[someObject shouldNot] beNil]; [[someObject should] have:count] rows]; };
Execute parametrized block wherever you need it, i usually do this within it's block
context(@"when adding object", ^{
beforeAll(^{
[someObject addObject:anotherObject];
});
it(@"it should have 1 object", ^{
testCount(1);
});
});
I hope this helps
Upvotes: 0
Reputation: 1263
I ended up creating a macro that generates the if(..., ^{ });
This will show the correct error message if the test failed, but you can not debug :( .
Here is an example of how it looks like:
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(@"[email protected]")
email_should_be_valid(@"[email protected]")
email_should_be_valid(@"[email protected]")
#undef email_should_be_valid
I will not mark this answer as correct, hope somebody comes with a better solution for this.
Upvotes: 0