

Sync your project in Android Studio to include the JaCoCo Gradle task and classes that will enable you to generate code coverage for your app.Īfter enabling JaCoCo in your project, generate your first code coverage in HTML format. ProguardFiles getDefaultProguardFile( 'proguard-android-optimize.txt'), 'proguard-rules.pro' tFrom(files())ĬtFrom(files())ĮtFrom(fileTree(dir: " $buildDir", includes: [ Then it’s time to write some unit tests for your project so JaCoCo can generate a report for you: fun counttext () /src/main/java"

To begin, make sure you’re familiar with the following prerequisites:

You’ll write a unit test, add JaCoCo to your project, and automate the process using GitHub Actions. Implementing Code Coverage in Androidįirst, let’s walk through how to implement code coverage in your Android project. If you’d like, you can check out this tutorial’s GitHub repo. In this article, you’ll learn how to integrate JaCoCo, a free code coverage library in Java, into your Android project, then generate a report for analysis with Codecov. In short, knowing your percentage of code coverage, and what it means, can help you write better tests for your apps, which leads to building better apps. Codecov works in tandem with your continuous integration (CI) system to analyze every commit, so you get insight into how your tests are performing right in your own workflow.

Reporting tools like Codecov can take your code coverage report and turn it into meaningful data, like how pull requests will affect code coverage. You know testing your code is important-but how effective are your tests? How many lines of code does it address, and does it touch enough of the subroutines? Code coverage is the measurement of how much of your source code a test covers, and understanding it can go a long way toward being confident in your test results.
