For Java based project we can get code coverage in following way
To get coverage for complete module ->
- Running coverage for complete project module. Run following command ->
bazel coverage ... --compilation_mode=dbg --subcommands --announce_rc --verbose_failures --jobs=auto --sandbox_debug --build_runfile_links --combined_report=lcov --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
- Then run following command from parent project directory to get html view. Html report is generated in
output-directory-name
we specified. From that open index.html
to see coverage report.
genhtml -o <output-directory-name> bazel-out/_coverage/_coverage_report.dat
bazel-out
directory usually gets created in project parent directory(e.g. where bazel WORKSPACE
file is present)
To get coverage for specific IT/Test in a module ->
- Running coverage for for specific IT/Test in a module. Run following command from project/sub-project directory ->
bazel coverage <class-name-of-Test-or-IT> --compilation_mode=dbg --subcommands --announce_rc --verbose_failures --jobs=auto --sandbox_debug --build_runfile_links --combined_report=lcov --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
- Then run following command from parent project directory to get html view. Html report is generated in
output-directory-name
we specified. From that open index.html
to see coverage report.
genhtml -o <output-directory-name> bazel-out/_coverage/_coverage_report.dat
ERROR: output '_coverage/_coverage_report.dat' was not created
when runbazel coverage
– Subantarctic