-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjacoco.gradle
84 lines (72 loc) · 2.27 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
def reportExclusion = [
'**/databinding/**/*.*',
'**/android/databinding/*Binding.*',
'**/BR.*',
'**/R.*',
'**/R$*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*_MembersInjector.*',
'**/Dagger*Component.*',
'**/Dagger*Component$Builder.*',
'**/*Module_*Factory.*',
'**/*Module*.*'
]
def validationExclusion = [
'*Fragment*',
'*Activity*',
'*Adapter*',
'*ViewPager*',
'*View*',
'*ViewGroup*',
'*Layout*',
'*ViewHolder*',
]
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
html.enabled(true)
csv.enabled(true)
xml.enabled(true)
}
def javaBuildTree = fileTree(
dir: "build/intermediates/javac/debug/",
excludes: reportExclusion
)
def kotlinBuildTree = fileTree(
dir: "build/tmp/kotlin-classes/debug/",
excludes: reportExclusion
)
def javaMainSrc = "${project.projectDir}/src/main/java/"
def kotlinMainSrc = "${project.projectDir}/src/main/kotlin/"
sourceDirectories.from = files([javaMainSrc, kotlinMainSrc])
classDirectories.from = files([javaBuildTree, kotlinBuildTree])
executionData.from = files("${project.buildDir}/outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
}
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: 'testDebugUnitTest') {
group = "Verification"
description = "Assert minumun coverage in the project."
sourceDirectories.setFrom jacocoTestReport.sourceDirectories
classDirectories.setFrom jacocoTestReport.classDirectories
executionData.setFrom jacocoTestReport.executionData
violationRules {
rule {
element = 'CLASS'
limit {
counter = 'BRANCH'
minimum = 0.5
}
excludes = validationExclusion
}
}
}
check.dependsOn jacocoTestCoverageVerification
android.testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
}
}