1
我为一个委托对象设置了一个模拟对象,以检查URL何时为零,委托方法以nil作为参数调用。当参数不是预期的参数时,OCMock抛出NSInternalInconsistencyException
当FileDownloadOperation
表现符合预期时,测试通过,这很好。
当FileDownloadOperation
未调用委托方法时,测试将按预期失败。
但当FileDownloadOperation
调用比nil
别的东西的委托方法,而不是失败,测试崩溃并没有其他的测试执行,因为OCMock
抛出:
“NSInternalInconsistencyException”的原因:“OCMockObject [FileDownloadOperationTest]:意外的方法调用:数据:<> forURL:无
-(void) testNilURL{
// 1. Create an operation
FileDownloadOperation * anOp = [[FileDownloadOperation alloc]init];
// 2. set a nil URL
anOp.URL = nil;
// 3. set a mock delegate
id mockDelegate = [OCMockObject mockForClass:[self class]];
[[mockDelegate expect] data:[OCMArg isNil] forURL:[OCMArg isNil]];
anOp.delegate = mockDelegate;
// 4. launch operation
[anOp main];
// 5. ASSERT mock delegate is called with nil data
STAssertNoThrow([mockDelegate verify], @"Delegate should be called with nil data and nil URL");
[anOp release];
}
它是预期的行为?还是我做错了什么? 谢谢!
这是在安装iOS 5.0模拟器解决,现在OCMock只是报告测试失败。 – yonix 2011-11-10 11:50:32