Skip to content

Instantly share code, notes, and snippets.

@Pegolon
Last active September 27, 2018 13:10
Show Gist options
  • Save Pegolon/fe731ccc68ba9a2516de1ce155082173 to your computer and use it in GitHub Desktop.
Save Pegolon/fe731ccc68ba9a2516de1ce155082173 to your computer and use it in GitHub Desktop.
#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