Android automatic and manual testing using Jacoco

Code Coverage:

Code Coverage is a method of finding out the measure of the developed source code while performing unit and functional testing.

Jacoco:

Jacoco is a very effective and promising open-source Code Coverage library developed by EclEmma team for Java and Android projects.

Code Coverage can be easily achieved for unit and functional tests for either of the testing ways mentioned below:

a. Automation Testing

b. Manual Testing

Automation Testing Steps in Android:

  1. First install Android Studio and import an working Android project
  2. Configure build gradle

Go to app/build.gradle path in the project and then add this:

also add this under buildtypes:

3. Execute and generate Code Coverage report using gradle command

To generate the code coverage report you need to build a gradle task in build.gradle file like below:

Now execute below command to generate the report:

Open the index.html file in app/build/reports/jacoco/jacocoTestReport/html/ folder and have a look.

Manual testing Steps in Android:

To test it out, put below code in onPause() or some other lifecycle method of an Activity.

Run the app and do your testing. Once you are done execute the following adb command to pull the coverage file from sdcard:

‘app/build/outputs/coverage.exec’ denotes the path where the coverage file needs to be copied in the project workspace. Delete if already exist any .exec file this directory.

Now you can either generate the report using the gradle task been shown earlier or you can import the .exec file in android studio by following:

Analyze -> Show coverage data -> import the .exec file

It will show the code coverage report.

--

--

Senior Android Engineer @Delivery Hero | Android developer | Kotlin lover | Flutter explorer | Problem Solver

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Md Ali Hossain

Senior Android Engineer @Delivery Hero | Android developer | Kotlin lover | Flutter explorer | Problem Solver