Im a beginner to OCMock and I need to verify if a method is invoked from another class. The following is my code.
//Creating the OCMockObject
id mockProductRequest = [OCMockObject mockForClass:[ProductRequest class]];
[[mockProductRequest expect] testProductRequest];
//Creating the object where the mock object will be invoked
ProductService *actualService = [[ProductService alloc] init];
[actualService testProductService];
[mockProductRequest verify];
-(void)testProductService{
//Method where the mock object's method is invoked
ProductRequest *request = [[ProductRequest alloc] init];
[request testProductRequest];
}
I seems to always receive a method was not invoked exception. Please help me to figure out what I’m doing wrong here.
You have to replace the real request inside the real
ProductService. You can archiev this for example by making the request a property of theProductServicelike this:and then exchange the real ProductRequest with the mocked one like this