문제

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

도움이 되었습니까?

해결책

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.
.....

다른 팁

Please refer to this answer. https://stackoverflow.com/a/25029501/973483

You should be able to use jacoco and enable code coverage on android project as long as you are using Java version 1.5. It should work with mockito, dagger and espresso.

If you, however, switch to Java 1.6 or above, you will have issues enabling code coverage

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top