I am using Mockito framework. I am facing issues mocking calls of another class from a class which i am unit testing. When the method2 is called from Class1, the call doesn't reach to mockCalls to return desired object.
Code to unit test Class1:
-(void)test_success {
self.restService = mock([Class2 class]);
[self mockCalls:self.restService withResult:someObject];
Class1 *sut = [[Class1 alloc] initWith:self.restService];
XCTestExpectation *expectation = [self expectationWithDescription:@"expectation"];
[sut someMethod:@"abc" parameter2:@"123456" parameter3:@"abcd" success:^(someObject) {
[expectation fulfill];
XCTAssertNotNil(someObject, @"object was null");
} failure:^(NSError *error) {
XCTFail(@"NSError not expected");
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
if (error != nil) {
XCTFail(@"Expectation Failed with error: %@", error);
}
}];
}
-(void)mockCalls:(Class2 *)mock withResult:(SomeClass *)someObject {
[givenVoid([mock method2:anything()
parameter2:anything()
parameter3:anything()
success:anything()
failure:anything()]) willDo:^id (NSInvocation *invocation) {
NSArray *args = [invocation mkt_arguments];
void(^success)(someObject) = args[3];
success(someObject);
return nil;
}];
}
Aucun commentaire:
Enregistrer un commentaire