Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. apply plugin: 'com.android.application'
  2. apply plugin: 'jacoco'
  3.  
  4. android {
  5. compileSdkVersion 22
  6. buildToolsVersion "22.0.1"
  7.  
  8. defaultConfig {
  9. applicationId "ninja.bryansills.jacocotest"
  10. minSdkVersion 16
  11. targetSdkVersion 22
  12. versionCode 1
  13. versionName "1.0"
  14.  
  15. testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  16. }
  17.  
  18. packagingOptions {
  19. exclude 'LICENSE.txt'
  20. }
  21.  
  22. compileOptions {
  23. sourceCompatibility JavaVersion.VERSION_1_7
  24. targetCompatibility JavaVersion.VERSION_1_7
  25. }
  26.  
  27. buildTypes {
  28. release {
  29. minifyEnabled false
  30. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  31. }
  32. debug {
  33. testCoverageEnabled true
  34. }
  35. }
  36. }
  37.  
  38. dependencies {
  39. compile fileTree(dir: 'libs', include: ['*.jar'])
  40. compile 'com.android.support:appcompat-v7:22.1.1'
  41.  
  42. androidTestCompile 'com.android.support.test:runner:0.2'
  43. androidTestCompile 'com.android.support.test:rules:0.2'
  44. androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
  45. }
  46.  
  47. package com.example;
  48.  
  49. import android.os.Bundle;
  50. import android.support.test.runner.AndroidJUnitRunner;
  51. import android.util.Log;
  52.  
  53. import java.lang.reflect.Method;
  54.  
  55. public class AndroidJacocoTestRunner extends AndroidJUnitRunner {
  56.  
  57. static {
  58. System.setProperty("jacoco-agent.destfile", "/data/data/"+BuildConfig.APPLICATION_ID+"/coverage.ec");
  59. }
  60.  
  61. @Override
  62. public void finish(int resultCode, Bundle results) {
  63. try {
  64. Class rt = Class.forName("org.jacoco.agent.rt.RT");
  65. Method getAgent = rt.getMethod("getAgent");
  66. Method dump = getAgent.getReturnType().getMethod("dump", boolean.class);
  67. Object agent = getAgent.invoke(null);
  68. dump.invoke(agent, false);
  69. } catch (Throwable e) {
  70. Log.d("JACOCO", e.getMessage());
  71. }
  72. super.finish(resultCode, results);
  73. }
  74. }
  75.  
  76. android{
  77. ...
  78. defaultConfig {
  79. ....
  80. testInstrumentationRunner "com.example.AndroidJacocoTestRunner"
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement