如何根据单元测试xml结果 生成最终的测试报告

因此建议采用Running multiple tests方式 5.运行完成后将手机中的文件导出 adb -s $ANDROID_AVD_DEVICE pull /mnt/sdcard/rototium/TEST-all.xml 其中$ANDROID_AVD_DEVICE为参数化的手机序列号 6.在jenkins中任务构建完成后即可使用Publish JUnit test result report插件分析得出单元测试报告 ...
如何根据单元测试xml结果 生成最终的测试报告
使用robotium进行Android应用进行自动化测试,之前用TMTS框架,但收集到的单元测试结果常常会少掉一些用例集。。穷则思变,Android的测试框架主要是通过InstrumentationTestRunner对被测应用进行控制与执行,因此可以对InstrumentationTestRunner进行扩展以完成测试结果收集,然后通过jenkins的Publish JUnit test result report插件得到结果报告。
1.新建一个java package,新建一个java类
源码来自开源项目:https://code.google.com/p/nbandroid-utils/
源码中生成的TEST-all.xml结果文件位于/data/data/com.example/files目录下,要导出结果文件的话,需要手机拥有root权限,比较麻烦,因此下面修改了文件存放路径,有SD卡则文件位于SD卡的/robotium目录下
代码贴不下,详细代码请见http://blog.csdn.net/hunterno4/article/details/14485663
2.修改AndroidManifest.xml文件
将原来的:
[html] view plaincopy
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example" />
修改为:
[html] view plaincopy
<instrumentation
android:name="com.example.test.instrumentation.InstrumentationTestRunner"
android:targetPackage="com.example" />

3.修改Run Configurations
右键测试工程>Run as >Run Configurations
在Test栏中,勾选Run all tests in the selected project,or package
这样每次在Eclipse中运行时才会使用新的InstrumentationTestRunner
在Instrumentation runner处下拉选择新写的InstrumentationTestRunner
点击Apply完成设置

4.命令行下运行测试用例
Running all tests: adb shell am instrument -w com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner
Running a single testcase: adb shell am instrument -w -e class com.android.foo.FooTest com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner
Running multiple tests: adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/com.example.test.instrumentation.InstrumentationTestRunner
命令行下运行测试用例与平时一样,只要将原来的InstrumentationTestRunner换成新的InstrumentationTestRunner就行,
需要注意的是,由于每次命令行执行完毕,都会覆盖原有的TEST-all.xml文件,即如果采用Running a single testcase方式运行多个测试用例集,则最后结果只会记录最后一个用例集,因此建议采用Running multiple tests方式

5.运行完成后将手机中的文件导出
adb -s $ANDROID_AVD_DEVICE pull /mnt/sdcard/rototium/TEST-all.xml
其中$ANDROID_AVD_DEVICE为参数化的手机序列号

6.在jenkins中任务构建完成后即可使用Publish JUnit test result report插件分析得出单元测试报告2017-05-03
cdw 阅读 30 次 更新于 2025-08-12 22:13:30 我来答关注问题0
词典网在线解答立即免费咨询

报告相关话题

Copyright © 2023 cidian.nuo5.com - 词典网 打一生肖 英语单词  夜唱网  免费精准算命
返回顶部