1
- def androidExclusion = [
1
+ def reportExclusion = [
2
2
' **/databinding/**/*.*' ,
3
3
' **/android/databinding/*Binding.*' ,
4
4
' **/BR.*' ,
@@ -10,14 +10,20 @@ def androidExclusion = [
10
10
' **/Dagger*Component.*' ,
11
11
' **/Dagger*Component$Builder.*' ,
12
12
' **/*Module_*Factory.*' ,
13
- ' **/*Fragment*.*' ,
14
- ' **/*Activity*.*' ,
15
- ' **/*Adapter*.*' ,
16
- ' **/*ViewPager*.*' ,
17
- ' **/*ViewHolder*.*' ,
18
13
' **/*Module*.*'
19
14
]
20
15
16
+ def validationExclusion = [
17
+ ' *Fragment*' ,
18
+ ' *Activity*' ,
19
+ ' *Adapter*' ,
20
+ ' *ViewPager*' ,
21
+ ' *View*' ,
22
+ ' *ViewGroup*' ,
23
+ ' *Layout*' ,
24
+ ' *ViewHolder*' ,
25
+ ]
26
+
21
27
task jacocoTestReport (type : JacocoReport , dependsOn : [' testDebugUnitTest' ]) {
22
28
23
29
group = " Reporting"
@@ -30,11 +36,11 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
30
36
31
37
def javaBuildTree = fileTree(
32
38
dir : " build/intermediates/javac/debug/" ,
33
- excludes : androidExclusion
39
+ excludes : reportExclusion
34
40
)
35
41
def kotlinBuildTree = fileTree(
36
42
dir : " build/tmp/kotlin-classes/debug/" ,
37
- excludes : androidExclusion
43
+ excludes : reportExclusion
38
44
)
39
45
def javaMainSrc = " ${ project.projectDir} /src/main/java/"
40
46
def kotlinMainSrc = " ${ project.projectDir} /src/main/kotlin/"
@@ -43,11 +49,30 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
43
49
executionData. from = files(" ${ project.buildDir} /outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec" )
44
50
}
45
51
46
- task showCoverageReport (type : Exec , dependsOn : ' jacocoTestReport' ) {
47
- group = " Reporting"
48
- commandLine " open" , " ${ project.buildDir} /reports/jacoco/jacocoTestReport/html/index.html"
52
+ task jacocoTestCoverageVerification (type : JacocoCoverageVerification , dependsOn : ' testDebugUnitTest' ) {
53
+
54
+ group = " Verification"
55
+ description = " Assert minumun coverage in the project."
56
+
57
+ sourceDirectories. setFrom jacocoTestReport. sourceDirectories
58
+ classDirectories. setFrom jacocoTestReport. classDirectories
59
+ executionData. setFrom jacocoTestReport. executionData
60
+
61
+ violationRules {
62
+ rule {
63
+ element = ' CLASS'
64
+
65
+ limit {
66
+ counter = ' BRANCH'
67
+ minimum = 0.5
68
+ }
69
+ excludes = validationExclusion
70
+ }
71
+ }
49
72
}
50
73
74
+ check. dependsOn jacocoTestCoverageVerification
75
+
51
76
android. testOptions {
52
77
unitTests. all {
53
78
jacoco {
0 commit comments