How to retrieve test results when using “adb shell

2020-02-25 23:44发布

I'm executing some tests in my Android device by using the following command:

adb shell am instrument -w package.name/android.test.runner.AndroidJUnitRunner

I can see the test progress and simple results through STDOUT. But, does this process also generates a results file inside the device (xml, html, etc)? If yes, where is it stored?

Thanks

3条回答
乱世女痞
2楼-- · 2020-02-26 00:08

If you are executing your tests using AndroidTestOrchestrator your XML test results are generated and stored inside the devices storage/emulated/0/odo/ directory. So they can be accessed using:

adb pull storage/emulated/0/odo/

I'm not sure why this isn't mentioned anywhere in the documentation. This path is likely to be different for real devices, where I believe the results are outputted on the SDCARD somewhere.

查看更多
疯言疯语
3楼-- · 2020-02-26 00:19

But, does this process also generates a results file inside the device (xml, html, etc)?

No, it does not.

Report generation is generally handled at a higher layer than 'am instrument'. If you run your tests using Gradle, it should generate the report for you. I believe this is what Android Studio relies on as well.

If you must generate the report from the test itself, you can use a custom test runner. See this answer for one way to do it: http://www.stackoverflow.com/a/5574418/1999084

查看更多
地球回转人心会变
4楼-- · 2020-02-26 00:26

I had a similar problem (I wanted to have xml test reports for my Jenkins when it runs instrumentation tests on a device). I solved it by implementing the "android-xml-run-listener" (https://github.com/schroepf/TestLab/tree/master/android).

To use it simply add:

androidTestCompile 'de.schroepf:android-xml-run-listener:0.1.3'

to your build.gradle (note the androidTest prefix - this will not add code to your production app!).

To use it, add:

-e listener de.schroepf.androidxmlrunlistener.XmlRunListener

to your am instrument command.

And to retrieve the XML report file, use:

adb pull /storage/emulated/0/Android/data/<your-app-package-name>/files/report.xml
查看更多
登录 后发表回答