最近开发项目 总是出现各种意想不到的问题 简单的功能性问题 测试组的 那帮孩子都测不出问题来 天天就知道打游戏 最后感觉 还是得靠自己 靠谱些 于是就研究了下 单元测试 感觉还是蛮简单的 可能是我的认识还不够深 没有接触到真正的内核东西吧 废话不多说了 直接点实际的
1 怎么开始呢
(1)第一种方法 创建项目的时候 直接添加 点击添加单元测试
勾选 UnitTest UITest xcode7 以后 对UI的测试 也已经很成熟了
(2)第二种方法 添加到已有的项目中
在项目中你会看
这里简单的介绍下 .m 里面的几个方法作用
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
//初始化的代码,在测试方法调用之前调用
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
// 释放测试用例的资源代码,这个方法会每个测试用例执行后调用
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// 测试用例的例子,注意测试用例一定要test开头
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
// 测试性能例子
[self measureBlock:^{
// Put the code you want to measure the time of here.
// 需要测试性能的代码
}];
}
next
使用 command + U 开始测试
打绿色勾勾的 是测试通过的 红色叉叉的是测试有问题的
其它的各位自由发挥
最后注意一点的是 使用了 cocoapods 的同学 需要手动的配置下
info.plist 与你当前的项目的路径设置为一样的就可以了 直接copy就行 嘿嘿
search PathS 也是一样的 copy当前项目下的 search Paths
不然会报错位 找不到 哪些配置