Last active
September 27, 2018 13:10
-
-
Save Pegolon/fe731ccc68ba9a2516de1ce155082173 to your computer and use it in GitHub Desktop.
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
#pragma mark - Simple Unit Test | |
- (void)test_callSomeoneWith_giveSomething_getSomething { | |
MyClass *sut = [MyClass new]; | |
NSString *input = @„give something“; | |
NSString *expectedResult = @„get something“; | |
NSString *result = [sut callSomeoneWith:input]; | |
XCTAssertEqualObjects(result, expectedResult); | |
} | |
#pragma mark - Asynchronous unit test | |
- (void)test_eventuallyCallSomeoneWith_giveSomething_getSomething { | |
MyClass *sut = [MyClass new]; | |
NSString *input = @„give something“; | |
NSString *expectedResult = @„get something“; | |
XCTestExpection *expectation = [self expectationWithDescription:@„calling someone“]; | |
[sut callSomeoneWith:input completion:^(NSString *result) { | |
XCTAssertEqualObjects(result, expectedResult); | |
[expectation fulfill]; | |
}]; | |
[self waitForExpectations: @[expectation] timeout:1.0]; | |
} | |
#pragma mark - Mock test class | |
@interface TestableMyClass: MyClass | |
@property (nonatomic) BOOL networkCalled; | |
@end | |
@implementation TestableMyClass | |
- (void)remoteCall { | |
self.networkCalled = YES; | |
} | |
@end | |
- (void)test_callSomeplace_networkWasCalled { | |
TestableMyClass *sut = [TestableMyClass new]; | |
[sut callSomeplace]; | |
XCTAssertTrue(sut.networkCalled); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment