@@ -19,8 +19,72 @@ buildTypes {
19
19
20
20
![ Alt Text] ( https://github.com/azizcse/Android-code-coverage/blob/master/img/run_test.png )
21
21
22
- # Jacoco coverage report
22
+ # Code coverage with Jacoco
23
23
24
+ use jacoco in root gradle
25
+ ```
26
+ classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
27
+ ```
28
+ In app.gradle add below snippet
29
+
30
+ ```
31
+ apply plugin: 'jacoco'
32
+
33
+ jacoco {
34
+ toolVersion = "$jacocoVersion"
35
+ }
36
+
37
+ tasks.withType(Test) {
38
+ jacoco.includeNoLocationClasses = true
39
+ }
40
+
41
+ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
42
+
43
+ reports {
44
+ xml.enabled = true
45
+ html.enabled = true
46
+ }
47
+
48
+ def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
49
+ def debugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
50
+ def mainSrc = "$project.projectDir/src/main/kotlin"
51
+
52
+ sourceDirectories = files([mainSrc])
53
+ classDirectories = files([debugTree])
54
+ executionData = fileTree(dir: project.buildDir, includes: ['jacoco/testDebugUnitTest.exec',
55
+ 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
56
+ }
57
+
58
+ android {
59
+
60
+ sourceSets {
61
+ main.java.srcDirs += 'src/main/kotlin'
62
+ test.java.srcDirs += 'src/test/kotlin'
63
+ androidTest.java.srcDirs += 'src/androidTest/kotlin'
64
+ }
65
+
66
+ buildTypes {
67
+ debug {
68
+ testCoverageEnabled true
69
+ }
70
+ release {
71
+ minifyEnabled false
72
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
73
+ testCoverageEnabled true
74
+ }
75
+ }
76
+
77
+ testOptions {
78
+ execution 'ANDROIDX_TEST_ORCHESTRATOR'
79
+ animationsDisabled true
80
+
81
+ unitTests {
82
+ includeAndroidResources = true
83
+ }
84
+ }
85
+ }
86
+
87
+ ```
24
88
### Run below command in Android studio Terminal
25
89
26
90
* /gradlew jacocoTestReport*
0 commit comments