Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apply plugin: 'com.android.application'
- apply plugin: 'jacoco'
- android {
- compileSdkVersion 22
- buildToolsVersion "22.0.1"
- defaultConfig {
- applicationId "ninja.bryansills.jacocotest"
- minSdkVersion 16
- targetSdkVersion 22
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- }
- packagingOptions {
- exclude 'LICENSE.txt'
- }
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_7
- targetCompatibility JavaVersion.VERSION_1_7
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- debug {
- testCoverageEnabled true
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:22.1.1'
- androidTestCompile 'com.android.support.test:runner:0.2'
- androidTestCompile 'com.android.support.test:rules:0.2'
- androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
- }
- package com.example;
- import android.os.Bundle;
- import android.support.test.runner.AndroidJUnitRunner;
- import android.util.Log;
- import java.lang.reflect.Method;
- public class AndroidJacocoTestRunner 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);
- }
- }
- android{
- ...
- defaultConfig {
- ....
- testInstrumentationRunner "com.example.AndroidJacocoTestRunner"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement