/ReturnMethod Secret
Created
December 23, 2015 06:11
ReturnMethod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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