【发布时间】:2013-04-10 14:38:09
【问题描述】:
美好的一天, 我正在使用 OCHamcrest 和 OCMockito 开始我的使用 TDD 方法的道路,它们真的很酷的工具,但有一点我似乎不了解模拟协议并尝试评估参数。
考虑代码自带的例子:
- (void)testVerifyWithMatcherForPrimitive
{
NSMutableArray *mockArray = mock([NSMutableArray class]);
[mockArray removeObjectAtIndex:2];
[[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0]
removeObjectAtIndex:0]; // The 0 is a placeholder, replaced by the matcher
}
它按预期工作,但是当我尝试使用模拟协议复制它时,它总是通过测试,例如:
- (void)testFirstParameter
{
// given
id<TestProtocol> mockElement = mockProtocol(@protocol(TestProtocol));
// when
id toProcess = nil;
[mockElement process: toProcess];
// then
id firstArgumentMatcher = instanceOf([NSArray class]);
[[verify(mockElement) withMatcher: firstArgumentMatcher forArgument: 0] process: toProcess];
}
在这个测试中,我试图测试参数是 NSArray 类的实例,它不应该通过。你能帮我发现我做错了什么吗?
非常感谢,
路易斯·亚历杭德罗
【问题讨论】:
标签: ios unit-testing tdd ocmockito ochamcrest