1、 单元测试: 在Tests 里面,引入需要的累, 然后写有关的单元测试就好了。
尤其是在代码重构的时候,可以将重构的内容和旧的内容精心单元测试对比。
eg: 我们的router模块

2、 有关UITests的内容
这个算是集成测试吧。
主要步骤: 录制有关的自动化脚本 —— 修改 —— 运行 : 知道测试过了为止


有关示例代码:

UITableView 以及UICollectionView的滑动处理:
// 滑动到顶部
XCUIElementQuery *tablesQuery = app.tables;
XCUIElement* table = tablesQuery.firstMatch;
[table swipeDown];
// 可以查看一下tablesQueury 的table层次结构,然后进行获取。
// 判断元素是否存在
XCUIElement *iconDBackSpButton = app.buttons[@"icon d back sp"];
if (!iconDBackSpButton.exists) {
iconDBackSpButton = app.buttons[@"icon d back nor"];
}
[iconDBackSpButton tap];
XCTWaiter 这个工具不知道是干嘛的。 这个工具要使用的时候再去用一下。
Tests和UITests是有区别的:
Tests是可以引入文件进行单元测试
UITests 是ui的自动化测试
3、iOS上的代码覆盖率
在iOS运行的target上勾选上,然后运行test的内容 , 运行完毕就能够看到覆盖率了。
editor scheme —— test —— options —— gather coverage for (all target)
网友评论