单元测试-Xcode6以上

开始:本来凑着项目最近没什么跟进,顺便看看测试用例,网上一查?OCTest占据大多数,但是已经de p redepre

为什么要测试

  1. 找bugs - Find bugs
  2. 需求-Codify requirements

Xcode单元测试

Xcode单元测试包含在一个 XCTestCase 的子类中。依据约束,每一个 XCTestCase 子类封装一个特殊的有关联的集合,例如一个功能(例如添加用户,加减法)、用例或一个程序流

使用# 断言#来报告错误

XCTAssertEqual(value, expectedValue);
Use assertion APIs to report failures
## setUp & tearDown
setUp 在 XCTestCase 中的每一个测试运行前被调用,tearDown 在测试运行结束时被调用:

开始测试

  1. 添加tests
  2. 鉴定测试通过
  3. Write tests
  4. Write code that passes the tests
  5. 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]]


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部