Generate AndroidTest coverage report with Jacoco

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Generate AndroidTest coverage report with Jacoco脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Short version:

1) Upgrade your AndROId test Support Library (ATSL, currently version 0.4.1). This is the key point for 0.3.0 is buggy.

    androidTestCompile 'com.android.support.test:runner:0.4.1'
    // Set this dePEndency to use JUnIT 4 rules
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    // Set this dependency to build and run EsPresso tests
    androidTestCompile 'com.android.support.test.esPResso:espresso-core:2.2.1'
    // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'

2) Set testCoverageEnabled in debug closure

    debug{
        testCoverageEnabled true
    }

3) Run ./gradlew tasks you will see a task named createDebugAndroidTestCoverageReport. That is exactly the task to generate the report.

4) Run ./gradlew createDebugAndroidTestCoverageReport. Find the reports in app/build/reports/coverage/debug/index.htML. Voila!

Long version:

It is late October 2015 and android test tools are rapidly improving. Code coverage is a commonly used method to assist test case writing. But when you seArch the GOOGLE "android test coverage" or "android jacoco" you can hardly find a working solution.

The reason is that android have provided the support for the coverage report in gradle build System long time ago, BUT it broke afterwards. So you can find a demo in github https://github.com/srideviaishwariya/Automation-Tools-for-Android/tree/master/Sample1. The codes is using out-dated android build tools which means, you copy the code and use the latest android build tools and everything goes wrong.

Oleksandr Kucherenko wrote a post detailing how the android test coverage failed and a possible workaround in Jun 2015. At that time the latest android-support-test-runner version is 0.3.0.

The test coverage bug was not fixed until android team announced an update of Android Test Support Library in Sep 2015. The post itself only mentioned the jacoco bug is fixed and nothing more, leaving the google search results are still presenting the old wrong way or work arounds with old test runners.

脚本宝典总结

以上是脚本宝典为你收集整理的Generate AndroidTest coverage report with Jacoco全部内容,希望文章能够帮你解决Generate AndroidTest coverage report with Jacoco所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。