← Back to list

Boost Your Android App Quality with Unit Tests and Code Coverage reports [2025 Version]

These reports will help you to write effective unit tests and measure code’s quality to build more reliable and bug-free Android apps.

Riazul Karim Ivan · 2025-08-20 09:07 · 0 claps · 2.9 min read
#android-development #unit-testing #code-coverage #jacoco #clean-code
Open on Medium ↗
Wiki topics: RAG · RAG & Retrieval 📱 · Mobile Development

Boost Your Android App Quality with Unit Tests and Code Coverage reports [2025 Version]

These reports will help you to write effective unit tests and measure code’s quality to build more reliable and bug-free Android apps.

Unit testing is a fundamental practice for writing reliable and maintainable Android applications. It ensures that your code behaves as expected, reduces bugs, and provides confidence when refactoring or adding new features. In this blog, we’ll walk through the steps of writing unit tests for an Android native app, generating reports, and analyzing code coverage.

Step 1. Configure Testing Libraries

Before writing tests, you need to configure the testing libraries in your project. Popular choices for Android include:

  • JUnit — the standard framework for writing unit tests.
  • MocKK — for mocking dependencies, coroutines.
  • Turbine — for flow testing.
dependencies 
{
    //... other libs

    // Core testing
    testImplementation(libs.junit)
    testImplementation(libs.androidx.core.testing) // For InstantTaskExecutorRule
    // Coroutines testing
    testImplementation(libs.kotlinx.coroutines.test) 
    testImplementation(libs.kotlin.test) // for kotlin.test.assertEquals
    // --- MockK (for mocking coroutines, suspend functions, etc.) ---
    testImplementation(libs.mockk)
    // --- Turbine (Flow testing) ---
    testImplementation(libs.turbine)
}

With these libraries configured, you are ready to write tests for your app logic.

Step 2: Writing Unit Tests for Your Business Logic

In an Android app, the ViewModel layer often contains the core business logic. Unit tests focus on this logic independently of the UI. For example:

[embed]

Unit tests help verify that your logic works correctly under different scenarios without running the full application.

Step 3: Run and Generate Unit Test Reports

Once your tests are written, you can run them from Android Studio or the command line:

./gradlew testDebugUnitTest
or
./gradlew testReleaseUnitTest

After running tests, you can check the results in the HTML report:

HTML Report Path: app/build/reports/tests/testDebugUnitTest/index.html

This report will be something like this:

Fig: Gradle Unit test report

Fig: Gradle Unit test report

This report provides detailed information on passed, failed, and skipped tests, making it easy to monitor your app’s stability.

Step 4: Lint Report

Lint analysis helps identify potential bugs, performance issues, or code style violations. Run lint with:

./gradlew lint

The HTML lint report can be found at:

HTML Report Path: app/build/reports/lint-results-debug.html

This report will be something like this:

Fig: Lint report

Fig: Lint report

Lint reports are valuable for maintaining code quality alongside unit tests.

Step 5: Configure Code Coverage

Code coverage ensures that your tests are effectively exercising your code. In Android, JaCoCo is a popular choice for generating coverage reports.

You can configure JaCoCo on app/build.gradle.kts

[embed]

Remember this: This task will depend on your unit test task (e.g., testDebugUnitTest or testReleaseUnitTest).

Please check which files are generated and use that file:

testDebugUnitTest.exec or testReleaseUnitTest.exec

Also Here Include only ViewModel classes, you can change this configurations based on your requirements

Step 6: Run the Report Generation task

After configuring JaCoCo, run your tests to generate the coverage report:

./gradlew jacocoTestReport

The generated HTML report provides a visual overview of how much of your code is covered:

JaCoCo Code Coverage Report Path: app/build/reports/jacoco/test/html/index.html

This report will be something like this:

Fig: JaCoCo Code Coverage Report

Fig: JaCoCo Code Coverage Report

Final Words — Benefits of Unit Tests and Code Coverage

Using unit tests and code coverage reports offers several benefits for developers, QA teams, and project owners:

  • Improved code quality — catch bugs early and reduce regressions.
  • Confidence in refactoring — safely improve and extend code.
  • Faster development cycles — tests automate validation, reducing manual QA.
  • Better decision-making — reports help prioritize fixes by showing failed tests, code coverage gaps, and lint warnings.
  • Reduced production risks — ensure critical logic is tested and secure before release.

Unit tests and coverage reports are not just a QA tool — they are a developer’s safety net. By integrating them into your Android project, you can ship higher-quality, risk-free code more confidently.

Source code and details configuration of android testing project: Github

AndroidDevelopment #UnitTesting #CodeCoverage #JaCoCo #CleanCode #MobileAppQuality #AndroidStudio #SoftwareTesting


메타데이터
post_id
cc2583a5c5ce
slug
boost-your-android-app-quality-with-unit-tests-and-code-coverage-cc2583a5c5ce
url
https://medium.com/@mrkivan820/boost-your-android-app-quality-with-unit-tests-and-code-coverage-cc2583a5c5ce
canonical_url
https://medium.com/@mrkivan820/boost-your-android-app-quality-with-unit-tests-and-code-coverage-cc2583a5c5ce
author_url
https://medium.com/@mrkivan820
status
ok
fetched_at
2026-07-18 02:57:34