E83001: code coverage below threshold

Category: E81xxx-E83xxx Test configuration, execution and coverage · Classification: COVERAGE_INSUFFICIENT · All error codes

What went wrong

Your code coverage is below the required threshold (80%). Tests passed, but insufficient code paths were exercised.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 811 (How do coverage thresholds and exit codes work in EK9?)
  • ek9 -q 206 (How do I measure test coverage in EK9?)

Coverage metrics

  • Method Coverage: percentage of functions/methods called
  • Line Coverage: percentage of source code lines executed
  • Branch Coverage: percentage of if/else, switch, loops exercised

How to fix it

  1. Check coverage report: `ek9 -t4 myfile.ek9` (detailed)
  2. Add tests for uncovered methods
  3. Test both branches of conditionals (true AND false)
  4. Test exception paths: `assertThrows Exception in funcThatThrows()`
  5. Test loop edge cases: empty, single, multiple items

Coverage files

.ek9/coverage-detail.json   // Uncovered items only
.ek9/coverage-verbose.json  // Complete breakdown

Common causes

  • Missing tests for certain functions
  • Only testing happy path (missing error/exception cases)
  • Loop bodies never entered (empty collections)
  • Dead code that cannot be reached

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E83001: code coverage below threshold - reported by the test runner, not the compiler, when ek9 -t greeting.ek9 runs in this project.

bad/greeting.ek9

#!ek9
defines module error.e83001.bad

  defines function

    greeting() as pure
      -> name as String
      <- result as String: `Hello, ${name}`

    shout() as pure
      -> name as String
      <- result as String: greeting(name).upperCase()

    whisper() as pure
      -> name as String
      <- result as String: greeting(name).lowerCase()

    padded() as pure
      -> name as String
      <- result as String: ` ${greeting(name)} `

bad/dev/tests.ek9

#!ek9
defines module error.e83001.bad.tests

  references
    error.e83001.bad::greeting

  defines program

    @Test
    GreetingIsKept()
      assert greeting("EK9") == "Hello, EK9"
$ ek9 -t greeting.ek9
ℹ️ Found 1 test:
  1 assert (unit tests with assertions)

Executing 1 test...

✅ PASS error.e83001.bad.tests::GreetingIsKept [Assert] (nms)

Summary: 1 passed, 0 failed (1 total)
Types: 1 assert
Duration: nms

❌ E83001: Code coverage 25.0% is below required threshold 80%
   Methods:  25.0% (1/4)
   Lines:    25.0% (3/12)

   Uncovered items:
     3 method(s)
       • error.e83001.bad::shout (./greeting.ek9:10)
       • error.e83001.bad::whisper (./greeting.ek9:14)
       • error.e83001.bad::padded (./greeting.ek9:18)

   Use -t4 or -t5 for detailed coverage report.
ek9: coverage below the required threshold (exit 12)

Fixed: Every function has a test

good/greeting.ek9

#!ek9
defines module error.e83001.good

  defines function

    greeting() as pure
      -> name as String
      <- result as String: `Hello, ${name}`

    shout() as pure
      -> name as String
      <- result as String: greeting(name).upperCase()

    whisper() as pure
      -> name as String
      <- result as String: greeting(name).lowerCase()

    padded() as pure
      -> name as String
      <- result as String: ` ${greeting(name)} `

good/dev/tests.ek9

#!ek9
defines module error.e83001.good.tests

  references
    error.e83001.good::greeting
    error.e83001.good::padded
    error.e83001.good::shout
    error.e83001.good::whisper

  defines program

    @Test
    GreetingIsKept()
      assert greeting("EK9") == "Hello, EK9"

    @Test
    ShoutIsUpperCase()
      assert shout("EK9") == "HELLO, EK9"

    @Test
    WhisperIsLowerCase()
      assert whisper("EK9") == "hello, ek9"

    @Test
    PaddedHasSpaces()
      assert padded("EK9") == " Hello, EK9 "
$ ek9 -t greeting.ek9
ℹ️ Found 4 tests:
  4 assert (unit tests with assertions)

Executing 4 tests...

✅ PASS error.e83001.good.tests::GreetingIsKept [Assert] (nms)
✅ PASS error.e83001.good.tests::PaddedHasSpaces [Assert] (nms)
✅ PASS error.e83001.good.tests::ShoutIsUpperCase [Assert] (nms)
✅ PASS error.e83001.good.tests::WhisperIsLowerCase [Assert] (nms)

Summary: 4 passed, 0 failed (4 total)
Types: 4 assert
Duration: nms

Found a problem?

If EK9 reported E83001 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.