开始:本来凑着项目最近没什么跟进,顺便看看测试用例,网上一查?OCTest占据大多数,但是已经de p redepre
为什么要测试
- 找bugs - Find bugs
- 需求-Codify requirements
Xcode单元测试
Xcode单元测试包含在一个 XCTestCase 的子类中。依据约束,每一个 XCTestCase 子类封装一个特殊的有关联的集合,例如一个功能(例如添加用户,加减法)、用例或一个程序流
使用# 断言#来报告错误
XCTAssertEqual(value, expectedValue);
Use assertion APIs to report failures
## setUp & tearDown
setUp 在 XCTestCase 中的每一个测试运行前被调用,tearDown 在测试运行结束时被调用:
开始测试
- 添加tests
- 鉴定测试通过
或 - Write tests
- Write code that passes the tests
- AKA “Test-Driven Development”
测试Target
Tests targets build bundles
Test code
Resources
Automatically included in new projects Existing projects can add test targets
Test Hosting(How tests are run)
Test bundles are executed by a host process
Injected into your app, or
Hosting process provided by Xcode
Resources for tests are not in the main bundle
Don’t use +[NSBundle mainBundle]
Use +[NSBundle bundleForClass:[MyTest class]]