下面使用android-junit-report工具实现android下junit框架测试自动生成报告,并发送邮件的功能
一、工具
1.android-junit-report------android下用该工具生成测试报告
download address:
https://github.com/jsankey/android-junit-report/downloads
2.(可选)android-junit-report-master----工具的源码和使用例子
download address:
https://github.com/jsankey/android-junit-report
二、使用
注:需要单独建一个测试工程,如果测试工程和项目工程是一个,ant debug install test 会报
\build.xml:617: subant task calling a target that depends on its parent target '-build-setup'.错误
1. * Edit AndroidManifest.xml to set android:name in the
instrumentation tag to:
com.zutubi.android.junitreport.JUnitReportTestRunner.
2. cmd: android update test-project -p [测试工程路径] -m [项目工程路径]
e.g.
android update project -p e:\workspace\dd -m E:\workspace\dd\TestCalTest
生成android自动化的build.xml, ant.properties, local.properties
3.* Edit ant.properties to add the line:
test.runner=com.zutubi.android.junitreport.JUnitReportTestRunner
4.编写 custom_rules.xml
<?xml version="1.0" encoding="UTF-8"?><project name="Test"><property name="reports.dir" value="bin/reprots"/><target name="makedir"><mkdir dir="${reports.dir}"/><echo>=====maked reports dir</echo></target><!-- 拿到项目工程的package名--><target name="init-props"><xpath input="${tested.project.dir}/AndroidManifest.xml"expression="/manifest/@package" output="tested.project.app.package"/></target><!-- 将测试报告从android目录下拿到pc上 --><target name="fetch-test-report" depends="init-props,makedir"><echo>Downloading XML test report...</echo><exec executable="${adb}" failonerror="true"><arg line="${adb.device.arg}"/><arg value="pull"/><arg value="/data/data/${tested.project.app.package}/files/junit-report.xml"/><arg value="${reports.dir}/junit-report.xml" /></exec></target><target name="test-and-fetch" depends="debug,install,test,fetch-test-report,send-mail"/><target name="send-mail"><mail mailhost="mail.foxitsoftware.com" mailport="25" subject="Test build"><from address="myself@xxx.com"/><to address="someone@xxx.com"/><message>test completed,see the file attachment </message><attachments><fileset dir="${reports.dir}"><include name="*.xml"/></fileset></attachments></mail></target><!-- use execute python --><target name="test"><exec executable="python" failonerror="true"><arg value="hello.py"/></exec></target></project>
最后只要到测试工程下运行 ant test-and-fetch
转载:http://blog.163.com/yujie_chen2011/blog/static/200379167201365104446774/