Open In App

How to Generate Global Coverage Report in Android Development using JaCoCo Plugin?

Improve
Improve
Like Article
Like
Save
Share
Report

TDD (Test-Driven Development) is vital in today’s android projects since it allows you to have more confidence in your code and codebases. Using frameworks like Espresso, Roboelectric, Mockito, and others, you can generally write good test cases. It’s perfectly OK to write test cases. But, more importantly, what exactly is the Global coverage for the test cases that you have built, which is what we refer to as Global code coverage. There are numerous plugins available, such as JaCoCo, SonarQube, and others.

JaCoCo is defined as follows, according to documentation:

In Java VM-based contexts, JaCoCo should be the standard technique for code coverage analysis. The goal is to provide a small, flexible, and well-documented library that can be used with a variety of build and development tools.

Now, let’s have a look at some practical approaches to reaching this goal step by step.

  1. Assumed that you’ve written some test cases for the application’s events. So, for one of the use scenarios where there are two displays A and B, we wrote an integration test.
  2. When a user clicks the button on-screen A, it launches screen B (explicit intent), and we are using the Espresso UI test framework to test for intent launching and information sharing across two screens.
  3. At the project and module levels, configure Gradle with the dependencies listed below.

Step by Step Implementation

Step #1: The Project Level (Gradle)

Image #1. Project Level (Gradle)

Step #2: Module Level (Gradle)

Image #2. Module Level (Gradle)

Step #3: Local debug test report

Image #3. The local test

Step #4: Now, from the terminal, type the following command to generate the following

(gradlew jacocoTestReport)to generate a global coverage report

Step #5: From an Android terminal, run the command below

<your system name>/<your project location>/app/build/reports/androidTests/connected/index.html

Step #6: Looking at the output logfile from Android Studio

To generate the test reports, type (gradlew createDebugCoverageReport) in the android studio terminal.

Image #4. The Android Studio Output


Last Updated : 26 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads