android UiAutomator修改UiAutomatorHelper生成测试报告

来源:互联网 发布:美甲软件 编辑:程序博客网 时间:2024/06/04 18:23

本人在学习UiAutomator的时候,发现UiAutomatorHelper快速调试类非常好用,最近想了一下利用UiAutomatorHelper类来生成一个测试报告,好得比那些乱七八糟的runlog好看多了。原理很简单,我就把我增加的代码贴出来好了。供大家参考,后期肯定好得做一些优化。

首先修改的是execCmd方法,其中在输出正确流的地方增加了一些判断。

while ((line = reader.readLine()) != null) {if (line.startsWith("INSTRUMENTATION_STATUS: test=")) {saveToFile("运行用例名称:"+getTest(line), "report.log", false);}if (line.startsWith("INSTRUMENTATION_STATUS: current")) {saveToFile("正在运行第"+getCurrent(line)+"个用例!", "report.log", false);}if (line.startsWith("INSTRUMENTATION_STATUS_CODE:")) {if (getCode(line).equalsIgnoreCase("-1")) {saveToFile("\n"+"---------------运行状态:运行错误!"+"\n", "report.log", false);}else if (getCode(line).equalsIgnoreCase("-2")) {saveToFile("\n"+"---------------运行状态:断言错误!"+"\n", "report.log", false);}else {saveToFile("运行状态:运行OK!", "report.log", false);}}System.out.println(line);saveToFile(line, "runlog.log", false);}


下面是一些提取有用信息的方法:

public String getTest(String text) {return text.substring(29, text.length());}public String getCode(String text) {return text.substring(29, text.length());}public StringgetCurrent(String text) {return text.substring(32, text.length());}public String getNow() {//获取当前时间Date time = new Date();SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String c = now.format(time);return c;}
生成报告的样子有点粗糙:

用例运行开始2017-04-12 17:01:02




运行用例名称:testAddAndDeleteAdress
正在运行第1个用例!
运行状态:运行OK!
运行用例名称:testAddAndDeleteAdress
正在运行第1个用例!


---------------运行状态:运行错误!


运行用例名称:testBuyCourseByWechat
正在运行第2个用例!
运行状态:运行OK!
运行用例名称:testBuyCourseByWechat
正在运行第2个用例!


---------------运行状态:断言错误!


运行用例名称:testChatroom
正在运行第3个用例!
运行状态:运行OK!
运行用例名称:testChatroom
正在运行第3个用例!


---------------运行状态:运行错误!


运行用例名称:testLearnCornerAddQuestion
正在运行第4个用例!
运行状态:运行OK!
运行用例名称:testLearnCornerAddQuestion
正在运行第4个用例!
运行状态:运行OK!
运行用例名称:testVerifyGradeInScreenAndMyInfo
正在运行第5个用例!
运行状态:运行OK!
运行用例名称:testVerifyGradeInScreenAndMyInfo
正在运行第5个用例!
运行状态:运行OK!

0 0
原创粉丝点击