【发布时间】:2014-05-06 11:16:48
【问题描述】:
我是 OCMockObjects 的新手,正在尝试模拟 ACAccount 类的实例方法:
-(NSArray *)accountsWithAccountType:(ACAccountType *)accountType;
我在测试类中写了这段代码来初始化mockObject:
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
id mockAccountStore = [OCMockObject partialMockForObject:accountStore];
[[[mockAccountStore stub] andReturn:@[@"someArray"]] accountsWithAccountType:[OCMArg any]];
//call the test method
[myClassInstance methodToTest];
在 myClass 中,methodToTest 如下所示:
-(void) methodToTest
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType* accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray* expectedArray = [accountStore accountsWithAccountType:accountType];
//Getting nil value to Array rather than the returned value in stub
}
知道我在这里做错了什么。谢谢。
【问题讨论】: