How to obtain code coverage from manual testing on android application (Android studio and gradle)?

  • Currently, I'm researching about GUI automated testing on Android and for some reason, I need a tool that can generate code coverage report from manual testing. After a long searching, I found that Jacoco and Emma mention the manual approach on their website. But unfortunately, There is not any up-to-date-working example on the internet.

    I have tried a lot of suggesting solution, for example,!searchin/jacoco/manual$20android|sort:date/jacoco/vx0g_6TKY8Q/0Tg3fX84CAAJ .

    It generated a coverage.exec but the file's size was only few byte (of course, Jacoco failed to generate any report from it.)

    Here is what I have tried:

    In app/build.gradle

    apply plugin: 'jacoco'
    jacoco {
    toolVersion ="0.7.8+"  //I did try "0.7.4+" as the suggest.
    task jacocoTestReport(type: JacocoReport) { … }



    In app/src/main/AndroidManifest.xml`

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


    protected void onStop()
    String TAG = "jacoco";
    try {
    String covPath = Environment.getExternalStorageDirectory().getPath() +     "/coverage.exec";
    File coverageFile = new File(covPath);
    Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
    Method dumpCoverageMethod =        emmaRTClass.getMethod("dumpCoverageData",coverageFile.getClass(),     boolean.class, boolean.class);
    dumpCoverageMethod.invoke(null, coverageFile, true, false);
    } catch (Exception e) {

    The emulator is Nexus 5 API 19 (I did try most of the versions.)
    The log from device EMMA: runtime coverage data merged into [/storage/sdcard/coverage.exec] {in 8 ms}
    The log after run ./gradlew jacocoTestReport Unable to read execution data file /Users/MyDummy/app/coverage.exec
    I'm using OSX10.12.3 if it related.

    To sum up, I need to know (or any working example) how to obtain code coverage while:

    Test the app manually.
    On Android application.
    Which is using Gradle not Maven or Ant.
    Android Studio not Eclipse.
    I see no way out and would really appreciate a help.

  • You might consider using a test coverage tool that isn't tied to the infrastructure in the way Emma is. This avoids the problems with incompatabilities with said infrastructure.

    Our Java Test Coverage tool instruments your source code, making it independent of the compiler and runtime system. You compile your code and execute/test it however your like (system tests, unit tests, manual interaction), and it collects test coverage data in a Java array in a TestCoverage class, as the tests run. At the end of execution (you define that, although exit from main is a common definition), that test coverage data is written somehow to a file, eventually to be displayed by the test coverage tool. While the Java Test Coverage tool provides a default class implementation that writes the array to a disk file using Java file primitives, you can easily override the implementation with any code you like, and store the array in any place where it can be eventually retrieved by another mechanism to be turned into a file, and then displayed.

    This will work with your manual exercising of code.

Suggested Topics

  • 2
  • 5
  • 2
  • 2
  • 2