-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjacoco.gradle
69 lines (59 loc) · 2.02 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
apply plugin: 'jacoco'
/**
* The correct path of the report is $rootProjectDir/app/build/reports/jacoco/index.html
* to run this task use: ./gradlew clean jacocoTestReport
*/
jacoco {
toolVersion = rootProject.jacocoVersion
}
def fileFilter = [
//Classes I intentionally don't want to test
'**/*Application.*',
'**/*Activity**',
'**/BuildConfig.*',
'**/*Fragment**',
'**/*View.*',
'**/*Adapter**',
'**/*ViewHolder**',
'**/extension/**',
'**/factory/*.*',
'**/utils/*.*',
'**/di/**',
'**/*Dagger**',
'**/*_MembersInjector.class',//Dagger2 generated code
'**/*_MembersInjector*.*',
'**/*_*Factory*.*',
'**/*Component*.*',
'**/*Module*.*',
'**/databinding/**',
'**/model/**'
]
def mainSrc = "${project.projectDir}/src/main/java"
def debugSrc = "${project.projectDir}/src/debug/java"
def javaDebugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug", excludes: fileFilter)
def kotlinDebugTree = fileTree(dir: "$buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
task jacocoTestReport(type: JacocoReport, dependsOn: ["testDebugUnitTest"]) {
group = "Reporting"
reports {
xml.enabled = true
html.enabled = true
}
sourceDirectories.from = files([mainSrc,debugSrc])
classDirectories.from = files([javaDebugTree, kotlinDebugTree])
executionData.from = fileTree(dir: "$buildDir", includes: [
'jacoco/testDebugUnitTest.exec',
'outputs/code_coverage/debugAndroidTest/connected/*coverage.ec'
])
doLast {
println "Wrote HTML coverage report to ${reports.html.destination}/index.html"
println "Wrote XML coverage report to ${reports.html.destination}"
}
}
task openJacocoTestReport {
group = "Reporting"
dependsOn 'jacocoTestReport'
doLast {
def path = project.file("build/reports/jacoco/jacocoTestReport/html/index.html")
exec { commandLine 'open', "$path" }
}
}