在测试类
-(void)testMyTest
{
MasterViewController* masterVC = [[MasterViewController alloc]init];//[OCMockObject mockForClass:[MasterViewController class]];
id master = [OCMockObject mockForClass:[DetailViewController class]];
[[master expect] getStringVal:@"PARAM"];
[masterVC doSomething];
[master verify];
}
详细视图控制器
-(NSString*)getStringVal:(NSString*)param
{
NSString *returnParam = [NSString stringWithFormat:@"%@-String",param];
return returnParam;
}
IN 主视图控制器
-(void)doSomething
{
DetailViewController *detail = [[DetailViewController alloc]init];
[detail getStringVal:@"PARAM"];
NSString * returnVal = [detail getStringVal:@"PARAM2"];
NSLog(@"returnVal %@",returnVal);
NSLog(@"doSomething");
}
当我运行测试时,我收到以下错误:
doSomething Unknown.m:0: 错误:-[iOS5ExampleTests testMyTest]:OCMockObject[DetailViewController]:未调用预期方法:getStringVal:@"PARAM"
看起来好像没有调用该方法。但是,如果我在该方法中设置断点,它会停止并向我显示该行已由应用程序执行,并且我也可以正确获取日志。