From 5a597c1ff8705588a70fdb3092a63b56ffb4c02a Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 3 Sep 2015 13:40:10 -0700 Subject: Fix instrumentation on connected tests JaCoCo was not setting its output file correctly and it ended up being attempted to be written to the root directory which didn't work. This is a temporary fix until an updated test runner comes out. --- app/build.gradle | 2 +- .../java/org/connectbot/FixJacocoTestRunner.java | 34 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/org/connectbot/FixJacocoTestRunner.java (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index e02e5bd..4200181 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,7 +44,7 @@ android { } testApplicationId "org.connectbot.tests" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "org.connectbot.FixJacocoTestRunner" } signingConfigs { diff --git a/app/src/androidTest/java/org/connectbot/FixJacocoTestRunner.java b/app/src/androidTest/java/org/connectbot/FixJacocoTestRunner.java new file mode 100644 index 0000000..fbadb9b --- /dev/null +++ b/app/src/androidTest/java/org/connectbot/FixJacocoTestRunner.java @@ -0,0 +1,34 @@ +/* + * This class comes from a StackOverflow post: + * http://stackoverflow.com/questions/30337375/empty-jacoco-report-for-android-espresso/31600193#31600193 + * + * This should be fixed in com.android.test.support:runner:0.4 and this class can be removed. + */ +package org.connectbot; + +import android.os.Bundle; +import android.support.test.runner.AndroidJUnitRunner; +import android.util.Log; + +import java.lang.reflect.Method; + +public class FixJacocoTestRunner extends AndroidJUnitRunner { + + static { + System.setProperty("jacoco-agent.destfile", "/data/data/" + BuildConfig.APPLICATION_ID + "/coverage.ec"); + } + + @Override + public void finish(int resultCode, Bundle results) { + try { + Class rt = Class.forName("org.jacoco.agent.rt.RT"); + Method getAgent = rt.getMethod("getAgent"); + Method dump = getAgent.getReturnType().getMethod("dump", boolean.class); + Object agent = getAgent.invoke(null); + dump.invoke(agent, false); + } catch (Throwable e) { + Log.d("JACOCO", e.getMessage()); + } + super.finish(resultCode, results); + } +} -- cgit v1.2.3