单元测试、调试与工具使用指南
1. 单元测试
在完成初步测试后,我们接着对不同方法进行测试。以下是具体的测试代码:
-(void) testDebugMeIsTrue {
BOOL result = [self.debugMe isTrue];
XCTAssertTrue(result, @"Expected DebugMe to be true, got %hhd", result);
}
-(void) testDebugMeIsFalse {
BOOL result = [self.debugMe isFalse];
XCTAssertFalse(result, @"Expected DebugMe to be false, got %hhd", result);
}
-(void)testDebugMeHelloWorld {
NSString * result = [self.debugMe helloWorld];
XCTAssertEqual(result, @"Hello World!",@"Expected debugMe hello world!, got %@", result);
XCTAssertEqual(@"3", @"3", @"Equal??");
}
成功编写了这些单元测试用例后,通常做法是为应用中的每个类编写一个测试类。有一种测试驱动开发(TDD)的方法,建议先编写测试用例,再编写应用代码。这样做的好处是,在开始编码前就清楚应用的预期行为。
另外,编写测试时还有一个有用的概念——模拟(mo
超级会员免费看
订阅专栏 解锁全文
6510

被折叠的 条评论
为什么被折叠?



