This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathjacoco.gradle
127 lines (108 loc) · 5.03 KB
/
jacoco.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
apply plugin: 'jacoco'
jacoco {
toolVersion = project.jacoco_version
// Custom reports directory can be specified like this:
// reportsDir = file("$buildDir/customJacocoReportDir")
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = false
}
project.afterEvaluate {
def productionReleaseVariant = android.applicationVariants.find { v -> v.name == "productionRelease" }
if (productionReleaseVariant != null) {
def variantName = productionReleaseVariant.name
def testTaskName = "test${variantName.capitalize()}UnitTest"
tasks.create(name: "unitTestCoverage", type: JacocoReport, dependsOn: "$testTaskName") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build."
reports {
html.enabled = true
xml.enabled = true
}
def excludes = [
'jdk.internal.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test.*',
'android/**/*.*',
'**/databinding/**/*.*',
'**/android/databinding/*Binding.*',
'**/BR.*',
'**/*_MembersInjector.*',
'**/Dagger*Component.*',
'**/Dagger*Component$Builder.*',
'**/*Module_*Factory.*',
'**/*_Factory.*',
'**/*Fragment*.*',
'**/*Application*.*',
'**/*Activity*.*',
'**/*ViewAdapter*.*',
'**/*JsonAdapter.*',
'**/*Dialog*.*',
'**/*Creator.class',
'**/*ViewPager*.*',
'**/*ViewHolder*.*',
'**/*Module*.*',
'**/fieldtests/*.*',
'**/widgets/*.*',
'**/remote/**',
'**/fieldtests/**/*.*',
'**/util/viewutils**'
]
def javaClasses = fileTree(dir: productionReleaseVariant.javaCompiler.destinationDir, excludes: excludes)
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}/uk", excludes: excludes)
classDirectories.from = files([javaClasses, kotlinClasses])
sourceDirectories.from = files([
"$project.projectDir/src/main/java",
"$project.projectDir/src/${variantName}/java",
"$project.projectDir/src/main/kotlin",
"$project.projectDir/src/${variantName}/kotlin"
])
executionData.from = files("${project.buildDir}/jacoco/${testTaskName}.exec")
}
}
def scenariosDebugVariant = android.applicationVariants.find { v -> v.name == "scenariosDebug" }
if (scenariosDebugVariant != null) {
def variantName = scenariosDebugVariant.name
tasks.create(name: "uiTestCoverage", type: JacocoReport, dependsOn: "connected${variantName.capitalize()}AndroidTest") {
group = "Reporting"
description = "Generate Jacoco UI test coverage reports for the ${variantName.capitalize()} build."
}
tasks.create(name: "uiTestCoverageReport", type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco UI test coverage reports for the ${variantName.capitalize()} build based on coverage.ac file."
reports {
html.enabled = true
xml.enabled = true
}
def includes = [
'**/*Activity.class',
'**/*Dialog.class',
// '**/widgets/*.*'
]
def excludes = [
'**/BaseActivity.class',
'**/TestSettingsActivity.class',
'**/Mock*Activity.class',
'**/DebugActivity.class',
'**/CircularProgressBar.class'
]
def javaClasses = fileTree(dir: scenariosDebugVariant.javaCompiler.destinationDir, includes: includes, excludes: excludes)
def kotlinClasses = fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", includes: includes, excludes: excludes)
classDirectories.from = files([javaClasses, kotlinClasses])
sourceDirectories.from = files([
"$project.projectDir/src/main/java",
"$project.projectDir/src/${variantName}/java",
"$project.projectDir/src/main/kotlin",
"$project.projectDir/src/${variantName}/kotlin"
])
def variantTestExecFolder = "${variantName}AndroidTest"
executionData.from = fileTree(dir: project.buildDir, includes: [
"outputs/code_coverage/${variantTestExecFolder}/connected/*.ec"
])
}
uiTestCoverage.dependsOn uiTestCoverageReport
}
}