0

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, https://groups.google.com/forum/#!searchin/jacoco/manual$20android%7Csort: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: https://github.com/kindraywind/MyDummy

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 jacoco-agent.properties

destfile=/storage/sdcard/coverage.exec

In app/src/main/AndroidManifest.xml`

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

In MainActivity.java

protected void onStop()
{
super.onStop();
if(BuildConfig.DEBUG)
{
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.

Woramet M
  • 1
  • 2

1 Answers1

-1

I've provided a detailed how-to guide on how to obtain code coverage during manual testing at my blog. Following it you should obtain a code coverage report. You seem to be headed in the right direction, but please read the post thoroughly.

A bit more advanced and complete solution is described in another blog post. It uses NanoHttpd to create a REST server on the device/emulator. The API provides a single endpoint that writes the report file as a response. Additionally, a custom (much faster) CSV report writer is provided.

Feel free to contact me if you want to discuss GUI automated testing (related to Android) further :)

curiousily
  • 91
  • 2
  • 10
  • 2
    In case the blog links go dead in the future, it would be helpful if you provided a brief explanation to help future readers with the same problem. Imagine your answer without the links and try to add all the information missing to successfully solve the problem. – Adalee Apr 20 '17 at 20:19