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,
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).
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With