Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Coverage in Android Studio with Sonar & Gradle

I am trying to get code coverage working for a new empty Android project using Gradle in Android Studio.

I managed to get Sonar working but I can't seem to figure it out for the code coverage. (never done anything like it before)

I have looked at JaCoCo but it is not compatible with Android. The same goes for Cobertura. And it seems Emma doesn't work with Gradle yet.

I am using Gradle 1.11, Android Studio 0.5.1 and Sonar Runner 2.3

like image 584
Tom Avatar asked Mar 12 '14 14:03

Tom


People also ask

Can Sonar be used for code coverage?

SonarQube and JaCoCo are two tools that we can use together to make it easy to measure code coverage. They also provide an overview of the overall health of the source code by finding code duplications, bugs and other issues in the code.

How do I get code coverage on Android?

You can check the code coverage report of your instrumented and unit tests locally. For your instrumented test, locate your Android studio projects folder in your system. Then navigate to your project folder: _(CodeCoverageExample) > app > build > reports > androidTests > connected > flavors > debugAndroidTest > Index.

How do I use SonarQube on Android?

File -> Settings -> Plugins -> then type sonarqube and click on Browse repositories at the bottom. Now on Android studio side your setup is done, run the command- gradle sonarqube to run the analysis.


1 Answers

JaCoCo is now supported in Android Studio when using build tools version 0.10.0

New Build System

Release Notes:

0.10.0
....
Test code coverage support with Jacoco
Enable in the tested Build Type with testCoverageEnabled = true
HTML and XML Report generated in build/reports/coverage
Configure version of Jacoco with

android {
  jacoco {
    version = '0.6.2.201302030002'
  }
}

Known issue: This is not compatible with using Dagger.
.....

like image 65
andrew Avatar answered Oct 31 '22 20:10

andrew