How do I measure test coverage in EK9?
← Testing · Ref: Q206
EK9 has built-in test coverage instrumentation. Use the -tC flag to enable coverage, with three modes and a configurable threshold.
COVERAGE FLAG
Run tests with coverage:
ek9 -tC myTests.ek9
Or: ek9 -t4 myTests.ek9 (JSON + coverage)
COVERAGE MODES
Three instrumentation modes:
SET - records whether each line was executed (default) COUNT - counts how many times each line ran ATOMIC - thread-safe counting for concurrent tests
THRESHOLD
The default coverage threshold is 80%. Tests fail if coverage falls below this. Configure in package settings.
OUTPUT FORMATS WITH COVERAGE
-t4 JSON output with coverage data -t5 Verbose coverage breakdown -t6 HTML dashboard with visual coverage
See Q207 for all output formats. See Q155 for basic testing. See Q157 for running tests. See Q321 for the quality report dashboard.
Example
defines module qa.testdeep.coverage defines function addNumbers() as pure -> a as Integer b as Integer <- rtn as Integer: a + b isPositive() as pure -> n as Integer <- rtn as Boolean: n > 0 defines program CoverageDemo() stdout <- Stdout() // === FUNCTIONS TO COVER === result <- addNumbers(3, 4) stdout.println(`3 + 4 = ${result}`) positive <- isPositive(5) stdout.println(`5 is positive: ${positive}`) negative <- isPositive(-1) stdout.println(`-1 is positive: ${negative}`) // === COVERAGE MODES === // Run with: ek9 -tC myTests.ek9 // SET - line executed yes/no // COUNT - execution count per line // ATOMIC - thread-safe counting stdout.println("Coverage: SET, COUNT, or ATOMIC modes") stdout.println("Default threshold: 80%") stdout.println("Formats: -t4 JSON, -t5 verbose, -t6 HTML")
Common mistakes
E08091 — The parameter n is declared but never used in the function body. All parameters must be referenced in the implementation. See ek9 -h E08091 for details.
Incorrect:
isPositive() as pure -> n as Integer <- rtn as Boolean: true
Correct:
isPositive() as pure -> n as Integer <- rtn as Boolean: n > 0
Other ways to ask this
- How does code coverage work in EK9?
- What coverage modes does EK9 support?
- How do I get a coverage report in EK9?
Coming from another language?
Java: JaCoCo or Cobertura external tools. Python: coverage.py with pytest-cov. Rust: cargo-tarpaulin or llvm-cov. Go: go test -cover built-in. Kotlin: JaCoCo via Gradle. EK9: built-in coverage with SET/COUNT/ATOMIC modes, 80% default threshold, HTML dashboard.
Keywords: percent, html, threshold, instrument, count, set, test, coverage, report, atomic