I have added testCoverageEnabled=true in my build.gradle file in order to start getting some code coverage reports.
Running my tests I can see that a code-coverage folder is added in my build outputs folders. However, when a reach its contents I see there is only a coverage.ec file...
What can I do with this file in order to get a recent report? Or what should I add to my build.gradle in order to get the full report?
(EDIT: My old answer used Jacoco to get code coverage. With Android Studio's latest updates, you can get code coverage without third party tools)
With the new Android Studio, you are able to run your unit tests and see the coverage all within the IDE.
First, you'll need to get your unit tests running in the IDE. (if you already can, then skip this step)
This guide and demo will help you.
Secondly, you'll need to create a JUnit Run configuration
Inside this configuraiton, you'll be able to choose
If you have any issue creating your JUnit Run Configuration, you should visit this guide for help.
Lastly, in the latest Android Studio, you should be able to run your JUnit-Run Configuration by clicking on the 'Run with Coverage' button.
Add the following to the "build.gradle" file
apply plugin: "jacoco"
Run the test using
gradlew :<module>:createDebugCoverageReport
Run the command from the project root replacing "module" with the name of the module under test.
The output should be in the module under "build/outputs/reports/coverage"
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