Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code coverage with jacoco for a Android library

I have an Android library (jar file) containing some APIs and I want to do code coverage test for these APIs using Jacoco.

For example, I have a calculator library (may name it calc.jar), having some APIs to do add, subtract, multiple and divide (via some static method such as Calc.doAdd(a,b), Calc.doSubtract(a,b) etc...). Now I have another Android test application (created by Android Studio) using this calculator library. I would like to do code coverage for this calculator library (surely I have calculator library source code).

I am also successfully do code coverage test with EMMA and ant. As Android Studio now uses Gradle for building, so I would like to know if we can do code coverage (I searched and see that Gradle can work with Jacoco).

I do searched and see that there are some topic relating to Jacoco code coverage for Android Application. But I am looking a way for doing code coverage for JAR library using Jacoco and Gradle. Please give me a help. If there are topics relating to this, please help to show me.

Many thanks in advance,

like image 499
Kratos TMT Avatar asked Aug 13 '15 03:08

Kratos TMT


People also ask

How do I get code coverage on Android?

Android Studio has a built-in feature that allows you to run tests with code coverage. Simply navigate to the src/test/java folder and right click. Then select Run 'Tests in 'java'' with Coverage (awkward use of single quotes theirs not mine).

How code coverage is calculated in JaCoCo?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100. 16) Where is the JaCoCo report generated Gradle?


1 Answers

According to Issue 76373 you can't get code coverage for libraries. Some people seems to have been successful with some hacks but I've not found anything that works for me.

like image 68
Prim Avatar answered Oct 05 '22 04:10

Prim