workaround for coverage bug (for now!)

see android bug report https://code.google.com/p/android/issues/detail?id=170607
This commit is contained in:
Vincent Breitmoser 2015-06-17 04:27:03 +02:00
parent 0d61221c5f
commit 8e60ccb650
2 changed files with 34 additions and 2 deletions

View File

@ -114,7 +114,7 @@ android {
versionCode 32300
versionName "3.2.3"
applicationId "org.sufficientlysecure.keychain"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "org.sufficientlysecure.keychain.JacocoWorkaroundJUnitRunner"
}
compileOptions {
@ -217,7 +217,10 @@ task jacocoTestReport(type:JacocoReport) {
"${buildDir}/generated/source/buildConfig/debug",
"${buildDir}/generated/source/r/debug"
])
executionData = files("${buildDir}/jacoco/testDebug.exec")
executionData = files([
"${buildDir}/jacoco/testDebug.exec",
"${buildDir}/outputs/code-coverage/connected/coverage.ec"
])
reports {
xml.enabled = true

View File

@ -0,0 +1,29 @@
package org.sufficientlysecure.keychain;
import java.lang.reflect.Method;
import android.os.Bundle;
import android.support.test.runner.AndroidJUnitRunner;
public class JacocoWorkaroundJUnitRunner 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 (Exception e) {
e.printStackTrace();
}
super.finish(resultCode, results);
}
}