-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation for coverage support (#1017)
* Documentation for coverage support * Coverage: update example script to use combined coverage report * Coverage docs: adding note about only being tested with ScalaTest
- Loading branch information
1 parent
a2f5852
commit 775b00a
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## Coverage support | ||
|
||
### Running tests with coverage | ||
|
||
rules_scala supports coverage, but it's disabled by default. You need to enable it with an extra toolchain: | ||
|
||
``` | ||
bazel coverage --extra_toolchains="@io_bazel_rules_scala//test/coverage:enable_code_coverage_aspect" //... | ||
``` | ||
|
||
It will produce several .dat files with results for your targets. | ||
|
||
You can also add more options to receive a combined coverage report: | ||
|
||
``` | ||
bazel coverage \ | ||
--extra_toolchains="@io_bazel_rules_scala//test/coverage:enable_code_coverage_aspect" \ | ||
--combined_report=lcov \ | ||
--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" \ | ||
//... | ||
``` | ||
|
||
This should produce a single `bazel-out/_coverage/_coverage_report.dat` from all coverage files that are generated. | ||
|
||
### Processing coverage reports | ||
|
||
You can install `lcov` package (that supports the format Bazel uses for coverage reports) to have access to additional tools: | ||
|
||
``` | ||
# Use your system package manager. E.g. on Ubuntu: | ||
sudo apt install lcov | ||
``` | ||
|
||
Having `lcov` package installed you can extract information from your coverage reports: | ||
|
||
``` | ||
# For a summary: | ||
lcov --summary your-coverage-report.dat | ||
# For details: | ||
lcov --list your-coverage-report.dat | ||
``` | ||
|
||
If you prefer an HTML report, then you can use `genhtml` provided also by the `lcov` package. | ||
|
||
An example with a bit of ceremony: | ||
|
||
```bash | ||
# Output html reports to a new directory. | ||
destdir="my-coverage-reports" | ||
mkdir -p ${destdir} | ||
|
||
# Generate HTML report from the results. | ||
genhtml -o ${destdir} --ignore-errors source bazel-out/_coverage/_coverage_report.dat | ||
|
||
echo "coverage report at file://${destdir}/index.html" | ||
|
||
``` | ||
|
||
### Support for testing frameworks | ||
|
||
Coverage support has been only tested with [ScalaTest](http://www.scalatest.org/). |