Skip to content

Commit 0538b6b

Browse files
Project Code Coverage
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent ec5adda commit 0538b6b

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

TESTING.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,12 @@ The code coverage report can be generated through Gradle with [JaCoCo plugin](ht
522522

523523
For unit test:
524524

525-
./gradlew codeCoverageReportForUnitTest
525+
./gradlew jacocoTestReport
526526

527527
For integration test:
528528

529-
./gradlew codeCoverageReportForIntegrationTest
529+
./gradlew :server:jacocoTestReport
530530

531-
For the combined tests (unit and integration):
532-
533-
./gradlew codeCoverageReport
534531

535532
To generate coverage report for the combined tests after `check` task:
536533

@@ -546,7 +543,7 @@ The report will be in XML format only by default, but you can add the following
546543

547544
For example, to generate code coverage report in HTML format and not in XML format:
548545

549-
./gradlew codeCoverageReport -Dtests.coverage.report.html=true -Dtests.coverage.report.xml=false
546+
./gradlew jacocoTestReport -Dtests.coverage.report.html=true -Dtests.coverage.report.xml=false
550547

551548
Apart from using Gradle, it is also possible to gain insight in code coverage using IntelliJ’s built-in coverage analysis tool that can measure coverage upon executing specific tests. Eclipse may also be able to do the same using the EclEmma plugin.
552549

gradle/code-coverage.gradle

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,47 @@ tasks.withType(JacocoReport).configureEach {
3434
}
3535
}
3636

37+
// Enhance jacoco report tasks to include all test types
38+
allprojects {
39+
plugins.withId('jacoco') {
40+
// Configure both jacocoTestReport and testCodeCoverageReport tasks
41+
tasks.matching { it.name == 'jacocoTestReport' || it.name == 'testCodeCoverageReport' }.configureEach {
42+
// Collect execution data files from all available test tasks
43+
def executionDataFiles = []
44+
def sourceSetsList = []
45+
46+
if (tasks.findByName('test')) {
47+
executionDataFiles.add("$buildDir/jacoco/test.exec")
48+
sourceSetsList.add(sourceSets.test)
49+
}
50+
51+
if (tasks.findByName('internalClusterTest')) {
52+
executionDataFiles.add("$buildDir/jacoco/internalClusterTest.exec")
53+
sourceSetsList.add(sourceSets.internalClusterTest)
54+
}
55+
56+
if (tasks.findByName('javaRestTest')) {
57+
executionDataFiles.add("$buildDir/jacoco/javaRestTest.exec")
58+
sourceSetsList.add(sourceSets.javaRestTest)
59+
}
60+
61+
// Set execution data and source sets
62+
if (!executionDataFiles.isEmpty()) {
63+
executionData.setFrom(files(executionDataFiles).filter { it.exists() })
64+
sourceSets(*sourceSetsList)
65+
}
66+
67+
// Only run if at least one execution data file exists
68+
onlyIf {
69+
file("$buildDir/jacoco/test.exec").exists() ||
70+
file("$buildDir/jacoco/internalClusterTest.exec").exists() ||
71+
file("$buildDir/jacoco/javaRestTest.exec").exists()
72+
}
73+
}
74+
}
75+
}
76+
77+
3778
if (System.getProperty("tests.coverage")) {
3879
reporting {
3980
reports {

0 commit comments

Comments
 (0)