How do I get a jacoco coverage report using Android gradle plugin 0.10.0 or higher?

前端 未结 5 1674
花落未央
花落未央 2020-11-28 03:22

I\'m trying to get a test coverage report using Gradle Android plugin 0.10.2. But I still can\'t get a coverage report after running some tests. (connectedAndroidTest).

5条回答
  •  广开言路
    2020-11-28 04:11

    Gradle already has built-in support for generating test coverage reports and we don't need to create any additional configurations or add any plugins to generate test coverage report. Basically, the only thing we need to do, is to set testCoverageEnabled parameter to true in build.gradle file as follows:

    android {
       buildTypes {
          debug {
             testCoverageEnabled = true
          }
       }
    }
    

    Next, we can execute the following Gradle task from CLI:

    ./gradlew createDebugCoverageReport
    

    On Windows, we can execute it like this:

    gradlew.bat createDebugCoverageReport
    

    Task will analyze code of our project in /src/main/java/ directory and unit tests placed in /src/androidTest/java/ directory. After executing this task, we can find test coverage report in the following directory of the module:

    /build/outputs/reports/coverage/debug/
    

    When we open index.html file, we can see visual report from test coverage, which can be viewed in a web browser.

    It looks as on the image below.

    article about test coverage report in Android application http://blog.wittchen.biz.pl/test-coverage-report-for-android-application/

提交回复
热议问题