-
Notifications
You must be signed in to change notification settings - Fork 3
/
jacoco.gradle
83 lines (74 loc) · 2.7 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
apply plugin: 'jacoco'
jacoco {
toolVersion "0.8.7"
}
if (isAndroidProject(project)) {
project.android {
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
}
project.afterEvaluate {
def testCoverageBuildType = rootProject.getProperties().get('testBuildType') ?: 'qa'
//Remember to change in sonarqube build.gradle config
def fileFilter = [
//Android stuff
'**/R.class',
'**/BR.class',
'**/R$*.class',
'**/BR$*.class',
'**/BuildConfig.*',
'android/**/*.*',
'**/Manifest*.*',
//Data Binding
'**/*databinding/**/*.*',
//Test
'**/**Test*.*',
//Interfaces
'**/interfaces/*.*',
//UI Related items that make no sense to add unit tests to
'**/views/*.*',
'**/dialogs/*.*',
'**/animation/*.*',
'**/UnfreezeScreenActivity.*',
//RxJava that also make no sense to test
'**/Schedulers.*',
//No logic utils
'**/utils/http/HttpCodes.*'
]
//'qa' is a default test build type. To change run:
//gradlew createGlobalSkeletoidUnitTestReport -PtestBuildType={yourTestBuildType}
task createModuleUnitTestReport(type: JacocoReport, dependsOn: ":$project.name:test${testCoverageBuildType.capitalize()}UnitTest") {
group = "Reporting"
def javaFileTree = fileTree(
dir: "${project.buildDir}/intermediates/javac/${testCoverageBuildType}/classes",
excludes: fileFilter
)
def kotlinFileTree = fileTree(
dir: "${project.buildDir}/tmp/kotlin-classes/${testCoverageBuildType}",
excludes: fileFilter
)
def coverageSourceDirs = [
"src/main/java",
"src/${testCoverageBuildType}/java"
]
getClassDirectories().from(files([javaFileTree, kotlinFileTree]))
getAdditionalSourceDirs().from(files(coverageSourceDirs))
getSourceDirectories().from(files(coverageSourceDirs))
getExecutionData().from(files("${project.buildDir}/jacoco/test${testCoverageBuildType.capitalize()}UnitTest.exec"))
reports {
xml.enabled = false
html.enabled = true
}
}
}
protected static boolean isAndroidProject(final Project project) {
final boolean isAndroidLibrary = project.plugins.hasPlugin('com.android.library')
final boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
return isAndroidLibrary || isAndroidApp
}