参考链接

objc中国 测试

实战

新建单元测试

File -> New -> Target -> Test -> iOS Testing Unit Bundle

CocoaPods ~ “Libraries not found”

Project -> Info -> Configuration -> Debug

将相应测试项目的 Based on Configuration File 选中 Pods.debug 即可。

测试异步代码

XCTest 为例

1
2
3
4
5
6
7
8
9
10
- (void)testThatItAppendsAString;
{
NSString *s1 = @"Foo";
XCTestExpectation *expectation = [self expectationWithDescription:@"Handler called"];
[s1 appendString:@"Bar" resultHandler:^(NSString *result){
[expectation fulfill];
XCTAssertEqualObjects(result, @"FooBar");
}];
[self waitForExpectationsWithTimeout:0.1 handler:nil];
}