2011-05-06 94 views
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]; 
    } 

它是预期的行为?还是我做错了什么? 谢谢!

+0

这是在安装iOS 5.0模拟器解决,现在OCMock只是报告测试失败。 – yonix 2011-11-10 11:50:32

回答

4

OCMock抛出异常来报告不匹配,相信OCUnit捕获并报告任何异常。但是due to a bug in the iOS Simulator,单元测试无法捕捉异常,所以只是崩溃。

(我目前正在写一个新的模拟框架,通过不依赖于异常解决此问题的作品。)

相关问题