Skip to content

Instantly share code, notes, and snippets.

@congpc
Created December 23, 2015 06:11
ReturnMethod
- (void)testReturnMethod_UsingClassMockAndStub {
//GIVEN
NSString* inputedValue = @"Simulated value";
id objectMock = OCMClassMock([ClassB class]);
OCMStub([objectMock executeReturnMethod]).andReturn(inputedValue);
//WHEN /* run code under test */
NSString* returnedValue = [objectMock executeReturnMethod];
//THEN
XCTAssertEqualObjects(inputedValue, returnedValue);
}
- (void)testReturnMethod_UsingPartialMockAndStub {
//GIVEN
NSString* inputedValue = @"Simulated value";
ClassB* object = [[ClassB alloc] init];
//You can comment these codes and run again.
id objectMock = OCMPartialMock(object); //Real object
OCMStub([objectMock executeReturnMethod]).andReturn(inputedValue);
//End comment
//WHEN /* run code under test */
NSString* returnedValue = [object executeReturnMethod];
//THEN
XCTAssertEqualObjects(inputedValue, returnedValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment