Test Coverage (scoverage)
Overview
- Uses
sbt-scoverageto measure line and branch coverage for Scala 2.13 and Scala 3 builds. - Global defaults: minimum 80% coverage, build fails if below.
How To Run Locally
- Quick aliases:
- From sbt shell:
cov(aggregate + single root HTML) orcovReport(current module HTML). - From terminal:
sbt covorsbt covReport.
- From sbt shell:
-
Per-module coverage report: 1)
sbt clean coverage test coverageReport2) Opentarget/scala-*/scoverage-report/index.htmlfor the current module. - Aggregate coverage across aggregated modules (root project):
1)
sbt clean coverage test coverageAggregate coverageReport2) The alias config avoids per-module HTML; open roottarget/scala-*/scoverage-report/index.htmlfor the combined report.
CI Usage
- Typical sequence:
clean; coverage; test; coverageAggregate. - XML output (for CI tooling) is written to
target/scala-*/scoverage-report/scoverage.xml.
Configuration
- Defined in
build.sbt:coverageMinimumStmtTotal := 80— required minimum statement coverage; adjust to taste.coverageFailOnMinimum := false— fail build if under the minimum.coverageHighlighting := true— better highlighting for coverage in reports.coverageExcludedPackages— excludes runner and samples packages by default.
On‑the‑fly Overrides
- For a one-off run:
sbt "set coverageMinimumStmtTotal := 85" clean coverage test coverageReport - To disable fail on minimum for local runs:
sbt "set coverageFailOnMinimum := false" coverage test
Expectations
- Target at least 80% coverage for core library code.
- Generated/entrypoint code (e.g., runner, samples) is excluded to keep focus on library logic.
Per‑module vs aggregate
- By default, the setup generates a single HTML report at the root when using
cov. - If you want individual project HTML reports, run
coverageReportafter switching to each project withproject <name>.
Troubleshooting
- If coverage is 0% across the board, ensure you ran
coveragebeforetest. - For multi-module runs, use
coverageAggregateat the root project.