How to Generate Global Coverage Report in Android Development using JaCoCo Plugin?
Last Updated :
26 Nov, 2021
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.
- 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.
- 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.
- 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
Similar Reads
How to Get the Connection Information in Android using Jetpack Compose? Many times while building an android application we require connection-related information about the android device such as IP address, link speed, and others within our android application. In this article, we will take a look at How to obtain connection-related information in the android applicati
4 min read
How to Generate SHA-1 Fingerprint of Keystore Certificate in Android Studio? SHA-1 stands for Secure Hash Algorithm 1 and it is used when you want to integrate google API into your app. There are multiple ways to SHA-1 Fingerprint but I'll show you the easiest way to get it. This is what SHA-1 Fingerprint looks like. Steps to Generate SHA-1 Fingerprint of Keystore Certificat
1 min read
How to generate automated test reports using Postman ? Postman is the API testing tool that helps to simplify the process of developing and testing APIs (Application Programming Interface). In this article, we will explore how to not only create environments but also generate automated test reports, enhancing efficiency and reliability in the API testin
2 min read
Working with Test Driven Development(TDD) in Android with Kotlin TDD is a software methodology, in which developers write tests for pieces of code prior to writing the code itself. If you are unfamiliar with this buzzword, please read this article first. In TDD, the test has to be written, followed by writing the code. The test may fail, the code will be updated,
5 min read
Get Battery Level in Android using Jetpack Compose Many times while building an android application if we have to run specific features within our android application we have to check the battery level of our android device. In this article, we will take a look at How to Check Battery Level in Android using Jetpack Compose.Step by Step Implementatio
2 min read
How to Generate Signed AAB File in Android Studio? In this article, you will learn how to create an Android App Bundle (AAB) file for an Android app. An Android App Bundle is a publishing format that includes all your appâs compiled code and resources. Your application should be digitally signed with a key in order to publish it on the Google Play s
2 min read