Skip to content

Commit b7402a7

Browse files
authored
[Feature] Code coverage for all projects (Azure#620)
1 parent 199a8e0 commit b7402a7

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

azure-communication-ui/build.gradle

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111
ui_library_version_code = getVersionCode()
1212

1313
kotlin_version = '1.7.20'
14-
jacoco_version = '0.8.7'
14+
jacoco_version = '0.8.8'
1515
junit_version = '4.13.2'
1616

1717
androidx_activity_ktx_version = '1.4.0'
@@ -83,6 +83,12 @@ plugins {
8383
}
8484

8585
allprojects {
86+
apply plugin: 'jacoco'
87+
88+
jacoco {
89+
toolVersion = "$jacoco_version"
90+
}
91+
8692
Properties localProps = new Properties()
8793
if (project.rootProject.file('local.properties').canRead()) {
8894
localProps.load(project.rootProject.file('local.properties').newDataInputStream())
@@ -116,6 +122,56 @@ subprojects {
116122
}
117123
}
118124

119-
task clean(type: Delete) {
125+
tasks.register("combinedCoverageReport", JacocoReport) {
126+
group = "Reporting"
127+
description = "Generate a Jacoco coverage report for debug unit tests in all subprojects"
128+
129+
def excludeFiles = [
130+
'**/R.class',
131+
'**/R$*.class',
132+
'**/*$ViewInjector*.*',
133+
'**/*$ViewBinder*.*',
134+
'**/BuildConfig.*',
135+
'**/Manifest*.*'
136+
]
137+
138+
def coverageSourceDirs = subprojects.collect {
139+
"$it.projectDir/src/main/java"
140+
}
141+
142+
def javaClasses = subprojects.collect {
143+
"$it.buildDir/intermediates/javac/debug"
144+
}.collect { path ->
145+
fileTree(dir: path, excludes: excludeFiles)
146+
}
147+
148+
def kc = subprojects.collect {
149+
"$it.buildDir/tmp/kotlin-classes/debug"
150+
}
151+
152+
def kotlinClasses = kc.collect { path ->
153+
fileTree(dir: path, excludes: excludeFiles)
154+
}
155+
156+
classDirectories.setFrom(files([javaClasses], [kotlinClasses]))
157+
sourceDirectories.setFrom(files(coverageSourceDirs))
158+
159+
def coverageExecPath = "outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
160+
executionData.setFrom(files(subprojects.findAll { proj ->
161+
def path = "$proj.buildDir/$coverageExecPath"
162+
(new File(path)).exists()
163+
}.collect { proj ->
164+
"$proj.buildDir/$coverageExecPath"
165+
}))
166+
167+
reports {
168+
xml.required = true
169+
html.required = true
170+
html.outputLocation = layout.buildDirectory.dir("reports/coverage/test/debug")
171+
xml.outputLocation = layout.buildDirectory.file("reports/coverage/test/debug/report.xml")
172+
}
173+
}
174+
175+
tasks.register("clean", Delete) {
120176
delete rootProject.buildDir
121177
}

azure-communication-ui/calling/jacoco.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
apply plugin: 'jacoco'
2-
3-
jacoco {
4-
toolVersion = "$jacoco_version"
5-
}
6-
71
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
82
def coverageSourceDirs = [
93
"src/calling/java"

eng/pipelines/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ steps:
8686
tasks: ':demo-app:assembleDebug --stacktrace'
8787

8888
- task: Gradle@2
89-
displayName: 'Coverage report for calling'
89+
displayName: 'Coverage report for all packages'
9090
inputs:
9191
workingDirectory: 'azure-communication-ui'
9292
gradleWrapperFile: 'azure-communication-ui/gradlew'
9393
gradleOptions: '-Xmx3072m'
9494
publishJUnitResults: false
95-
tasks: 'jacocoTestReport'
95+
tasks: ':combinedCoverageReport'
9696

9797
- task: PublishCodeCoverageResults@1
98-
displayName: 'Calling - Publish code coverage Jacoco'
98+
displayName: 'Calling - Publish code coverage report'
9999
inputs:
100-
summaryFileLocation: $(System.DefaultWorkingDirectory)/azure-communication-ui/calling/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
101-
pathToSources: $(System.DefaultWorkingDirectory)/azure-communication-ui/calling/src/main/java
102-
reportDirectory: $(System.DefaultWorkingDirectory)/azure-communication-ui/calling/build/reports/jacoco/jacocoTestReport/html/index.html
100+
summaryFileLocation: $(System.DefaultWorkingDirectory)/azure-communication-ui/build/reports/coverage/test/debug/report.xml
101+
reportDirectory: $(System.DefaultWorkingDirectory)/azure-communication-ui/build/reports/coverage/test/debug/index.html
103102

0 commit comments

Comments
 (0)