Jacoco converts coverage.ec into uncoated reports.

I managed to get a code coverage report by following these steps:

  • Enable coverage by the type of assembly you want (e.g. debugging)

    buildTypes { debug { testCoverageEnabled true } }

  • Apply Jacoco plugin and install version

    apply plugin: 'jacoco' jacoco { version "0.7.1.201405082137" }

  • Run

    ./gradlew createDebugCoverageReport

  • All tests in connectedAndroidTest are launched, and a coverage report is generated based on them. I can find coverage reports in

    app/build/outputs/reports/coverage/{buildType}/index.html

and coverage.ec file in

app/build/outputs/code-coverage/connected/coverage.ec

But there is no jacoco.exec, as I run from Android Instrumentation instead of Robolectric test cases.

And when I run the toolkit from ADB (I think it still uses Emma) as follows, I get the coverage.ec file as follows:

 $ adb shell am instrument -w -e coverage true -e coverageFile /sdcard/coverage.ec com.sample.helloworld.test/.Runner .... OK (4 tests) Generated code coverage data to /sdcard/coverage.ec 

But I can’t convert cover.ec to report using emma, because the coverage.em file is missing,

 java -cp ~/adt-bundle-mac-x86_64-20130729/sdk/tools/lib/emma_device.jar emma report -r html -in \ coverage.em,myFile.ec,myapp_coverage1.ec -sp /path/to/myapp/src 

Is there any way to solve this problem?

+4
source share
3 answers

Just use "cover.ec" as the ".exec" file, it worked for me

This is what Google did in the Android Gradle Plugin Source Code.

public static final String FILE_COVERAGE_EC = "coverage.ec";

in SimpleTestCallable.java in the com.android.builder.internal.testing package.

+7
source

I wrote an article about the same scenario and my solution. You can read it here . To answer this specific question, you should take the following steps: Change gradle to this:

 apply plugin: 'jacoco' jacoco { toolVersion = '0.7.5.201505241946' } 

Second download this jar . Keep doing what you did until you get the coverage.ec file. Then when you run it:

 java -jar android-jacoco-the-missing.jar -f /path/to/coverage.ec -p ./path/to/android/project 

And here it is! A folder with code coverage will be created in jar.

Another option is to use cover.ec with the Jenkins Jacoco plugin. But for this you need to enable Jenkins.

+4
source

Delete from the next team of his work for me

 java -jar android-jacoco-the-missing.jar -f /path/to/coverage.ec -p /path/to/android/project 
0
source

All Articles