Skip to content

Commit 05ceb15

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

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

TESTING.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,22 +518,48 @@ Example:
518518

519519
# Test coverage analysis
520520

521-
The code coverage report can be generated through Gradle with [JaCoCo plugin](https://docs.gradle.org/current/userguide/jacoco_plugin.html).
521+
The code coverage report can be generated through Gradle with [JaCoCo plugin](https://docs.gradle.org/current/userguide/jacoco_plugin.html). Following are some of the ways to generate the code coverage reports locally.
522522

523523
For unit test:
524524

525+
./gradlew test
525526
./gradlew jacocoTestReport
526527

528+
For unit test inside a specific module:
529+
530+
./gradlew :server:test
531+
./gradlew :server:jacocoTestReport
532+
533+
For specific unit test inside a specific module:
534+
535+
./gradlew :server:test --tests "org.opensearch.search.approximate.ApproximatePointRangeQueryTests.testNycTaxiDataDistribution"
536+
./gradlew :server:jacocoTestReport -Dtests.coverage.report.html=true
537+
527538
For integration test:
528539

540+
./gradlew internalClusterTest
541+
./gradlew jacocoTestReport
542+
543+
For integration test inside a specific module:
544+
545+
./gradlew :server:internalClusterTest
546+
./gradlew :server:jacocoTestReport
547+
548+
For specific integration test inside a specific module:
549+
550+
./gradlew :server:internalClusterTest --tests "org.opensearch.action.admin.ClientTimeoutIT.testNodesInfoTimeout"
529551
./gradlew :server:jacocoTestReport
530552

553+
For modules with javaRestTest:
554+
555+
./gradlew :qa:die-with-dignity:javaRestTest
556+
./gradlew :qa:die-with-dignity:jacocoTestReport -Dtests.coverage.report.html=true
531557

532558
To generate coverage report for the combined tests after `check` task:
533559

534560
./gradlew check -Dtests.coverage=true
535561

536-
The code coverage report will be generated in `build/codeCoverageReport`, `build/codeCoverageReportForUnitTest` or `build/codeCoverageReportForIntegrationTest` correspondingly.
562+
The code coverage report will be generated in `$buildDir/build/reports/jacoco/test/html/`.
537563

538564
The report will be in XML format only by default, but you can add the following parameter for HTML and CSV format.
539565

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

544570
For example, to generate code coverage report in HTML format and not in XML format:
545571

546-
./gradlew jacocoTestReport -Dtests.coverage.report.html=true -Dtests.coverage.report.xml=false
572+
./gradlew internalClusterTest -Dtests.coverage.report.html=true -Dtests.coverage.report.xml=false
547573

548574
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.
549575

gradle/code-coverage.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,24 @@ allprojects {
3939
plugins.withId('jacoco') {
4040
// Configure both jacocoTestReport and testCodeCoverageReport tasks
4141
tasks.matching { it.name == 'jacocoTestReport' || it.name == 'testCodeCoverageReport' }.configureEach {
42-
// Collect execution data files from all available test tasks
4342
def executionDataFiles = []
4443
def sourceSetsList = []
45-
4644
if (tasks.findByName('test')) {
4745
executionDataFiles.add("$buildDir/jacoco/test.exec")
4846
sourceSetsList.add(sourceSets.test)
4947
}
50-
5148
if (tasks.findByName('internalClusterTest')) {
5249
executionDataFiles.add("$buildDir/jacoco/internalClusterTest.exec")
5350
sourceSetsList.add(sourceSets.internalClusterTest)
5451
}
55-
5652
if (tasks.findByName('javaRestTest')) {
5753
executionDataFiles.add("$buildDir/jacoco/javaRestTest.exec")
5854
sourceSetsList.add(sourceSets.javaRestTest)
5955
}
60-
61-
// Set execution data and source sets
6256
if (!executionDataFiles.isEmpty()) {
6357
executionData.setFrom(files(executionDataFiles).filter { it.exists() })
6458
sourceSets(*sourceSetsList)
6559
}
66-
67-
// Only run if at least one execution data file exists
6860
onlyIf {
6961
file("$buildDir/jacoco/test.exec").exists() ||
7062
file("$buildDir/jacoco/internalClusterTest.exec").exists() ||

0 commit comments

Comments
 (0)