Android jacoco cover blank with gradle

I am trying to create jacoco to generate a code coverage report for my Android testing project. I have the following in build.gradle:

apply plugin: 'com.android.application' apply plugin: 'jacoco' ... jacoco { toolVersion = "0.7.1.201405082137" } ... android { buildTypes { release { } debug { testCoverageEnabled true } } } 

when I run gradlew -i createDebugCoverageReport, I get a coverage report, but it is empty. The end of gradle execution is as follows:

 :androidTest:connectedAndroidTest (Thread[main,5,main]) completed. Took 2 mins 36.951 secs. :androidTest:createDebugCoverageReport (Thread[main,5,main]) started. :androidTest:createDebugCoverageReport Executing task ':androidTest:createDebugCoverageReport' (up-to-date check took 0.006 secs) due to: Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug has changed. Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug/index.html has been removed. Output file /home/akos/src/androidTest/build/outputs/reports/coverage/debug/.resources/package.gif has been removed. [ant:reportWithJacoco] Loading execution data file /home/akos/src/androidTest/build/outputs/code-coverage/connected/coverage.ec [ant:reportWithJacoco] Writing bundle 'debug' with 3 classes :androidTest:createDebugCoverageReport (Thread[main,5,main]) completed. Took 0.215 secs. BUILD SUCCESSFUL Total time: 4 mins 53.467 secs 

indeed, the coverage.ec file above is empty (0 in length)

in the build / intermediates / coverage-instrumented-classes / directory, I seem to have files with a tool class

this is with gradle 2.1

what am I doing wrong?

+5
source share
7 answers

Yakoko should be inside the android closure, and the jacoco plugin declaration is optional:

 apply plugin: 'com.android.application' ... android { buildTypes { release { } debug { testCoverageEnabled true } } jacoco { toolVersion = "0.7.1.201405082137" } } 
+2
source

Try to create a debug lighting report using the Nexus device (5 or 5x), it will work fine. I ran into the same problem with Samsung devices (coverage.ec is empty), but after that I run it with Nexus 5x and everything works fine.

+2
source

I use the same gradle.build and just type the command below into the terminal. This gave me a coverage report and a test result in the form of an html page.

$. / gradlew createDebugCoverageReport

Another suggestion; enter terminal

$. / gradlew --gui

it opens a gui window and you can find the correct command.

+1
source

There is a problem in Android Gradle Plugin 0.14.0, which generates an empty coverage.ec file. It was known and was fixed in the branch, but does not seem to have published it yet: https://code.google.com/p/android/issues/detail?id=78556

On the other hand, a great template project for Android Studio can be found here using Jacoco and RoboElectric: https://github.com/nenick/android-gradle-template

So, you can wait for Google to fix it or use a different library repository, but the Android Studio 1.0.0 Gradle plugin is useless.

+1
source

I found a solution to the same problem from the Jacoco code coverage in Android Studio tastefully . He has an example of what to do if instead of testDebug.exec a .ec shell is created.

  • I created a jacocoTestReport task.

  • I executed $./gradlew createDebugCoverageReport which generates coverage.ec file

  • After that, I executed $./gradlew jacocoTestReport and created the HTML.
0
source

I made an interesting observation. I had the same problem with a coverage.ec File havinbg file of 0 bytes in size. I tried all the answers here the same way as these:

https://code.google.com/p/android/issues/detail?id=170607

Nothing changed. My build.gradle file has only these settings for jacoco to work:

 apply plugin: 'com.android.application' apply plugin: 'jacoco' android { ... buildTypes { ... debug { testCoverageEnabled true } } ... } 

My version of Android Studio is 1.2.2. I use the following gradle settings in "File -> Project Structure":

  • Gradle version: 2.2.1
  • Android Plugin Version: 1.2.3

I tried to run control tests with gradlew cC on Motorola Moto G 4G LTE - Android 4.4.4 with correctly tested instrumental tests, but with a coverage.ec file with 0 bytes. Today I tried another device: LG Spirit 4G LTE - Android 5.0 and now code coverage works !!! The coverage.ec file has 322 bytes, and I see the correct html coverage reports.

I think sometimes running gradle with gradlew cC --debug shows that `` cover.ec``` cannot be found on the device, and sometimes it shows a file that is being pulled. But perhaps in both situations it cannot be found on the device. Thus, choosing a different device may solve the problem. Good luck

0
source

Now (October 2015) you can use it as an android team fixed a bug .

 android { ... buildTypes { debug { testCoverageEnabled true } } ... dependencies{ androidTestCompile 'com.android.support.test:runner:0.4.1' // Set this dependency to use JUnit 4 rules androidTestCompile 'com.android.support.test:rules:0.4.1' // Set this dependency to build and run Espresso tests androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' // Espresso-contrib for DatePicker, RecyclerView, Drawer actions, Accessibility checks, CountingIdlingResource androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1' } } 

Then just use ./gradlew createDebugCoverageReport .

0
source

Source: https://habr.com/ru/post/1207176/


All Articles