Add guide for generating code coverage report in TESTING.md (#1264)

Signed-off-by: Tianli Feng <ftianli@amazon.com>
This commit is contained in:
Tianli Feng 2021-09-21 16:44:08 -07:00 committed by GitHub
parent 0ab8e34022
commit 20728c3725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 1 deletions

View File

@ -443,7 +443,37 @@ Multi-threaded tests are often not reproducible due to the fact that there is no
# Test coverage analysis
Generating test coverage reports for OpenSearch is currently not possible through Gradle. However, it *is* possible to gain insight in code coverage using IntelliJs 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.
The code coverage report can be generated through Gradle with [JaCoCo plugin](https://docs.gradle.org/current/userguide/jacoco_plugin.html).
For unit test:
./gradlew codeCoverageReportForUnitTest
For integration test:
./gradlew codeCoverageReportForIntegrationTest
For the combined tests (unit and integration):
./gradlew codeCoverageReport
To generate coverage report for the combined tests after `check` task:
./gradlew check -Dtests.coverage=true
The code coverage report will be generated in `build/codeCoverageReport`, `build/codeCoverageReportForUnitTest` or `build/codeCoverageReportForIntegrationTest` correspondingly.
The report will be in XML format only by default, but you can add the following parameter for HTML and CSV format.
- To generate report in HTML format: `-Dtests.coverage.report.html=true`
- To generate report in CSV format: `-Dtests.coverage.report.csv=true`
- To NOT generate report in XML format: `-Dtests.coverage.report.xml=false`
For example, to generate code coverage report in HTML format and not in XML format:
./gradlew codeCoverageReport -Dtests.coverage.report.html=true -Dtests.coverage.report.xml=false
Apart from using Gradle, it is also possible to gain insight in code coverage using IntelliJs 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.
Please read your IDE documentation for how to attach a debugger to a JVM process.