How do I run tests and see results in EK9?

← Testing · Ref: Q157

EK9 provides a built-in test runner with multiple output formats and coverage reporting. Use the -t flag to run tests from the command line.

THE -t FLAG
Run all tests in a file:

  ek9 -t file.ek9

This runs every @Test program and reports results in human-readable format.

OUTPUT FORMATS

EK9 supports multiple output formats:

  ek9 -t file.ek9    # Human-readable (default)
  ek9 -t0 file.ek9   # Terse (pass/fail only)
  ek9 -t2 file.ek9   # JSON (for AI/tool parsing)
  ek9 -t3 file.ek9   # JUnit XML (for CI integration)

RUNNING TEST GROUPS

Run a specific test group:

  ek9 -tg database file.ek9

This runs only tests marked with @Test: "database".

LISTING TESTS

List all tests without running them:

  ek9 -tL file.ek9

COVERAGE

Run tests with coverage reporting:

  ek9 -tC file.ek9   # Coverage summary after tests
  ek9 -t4 file.ek9   # Detail JSON coverage
  ek9 -t5 file.ek9   # Verbose coverage
  ek9 -t6 file.ek9   # HTML coverage report

Coverage must be at least 80% for packaging with -P.

EXIT CODES

The test runner uses specific exit codes:

  0  = all tests pass, coverage OK
  11 = one or more tests failed
  12 = tests pass but coverage below 80%

See Q155 for writing tests. See Q156 for assertions. See Q2 for compile and run. See Q204 for black-box testing. See Q206 for test coverage. See Q322 for profiling data. See Q628 for profiling tests. See Q749 for fuzzing overview. See Q754 for automatic test generation.

Example

defines module qa.testing.running

  defines function

    multiply() as pure
      ->
        first as Integer
        second as Integer
      <- rtn as Integer: first * second

  defines program

    // === BASIC TEST ===

    @Test
    MultiplyTest()
      stdout <- Stdout()
      result <- multiply(6, 7)
      assert result == 42
      stdout.println("6 * 7 = " + $result)

    // === GROUPED TEST ===

    // Run this group only with: ek9 -tg math file.ek9
    @Test: "math"
    AdditionTest()
      stdout <- Stdout()
      assert 2 + 2 == 4
      stdout.println("Addition test passed")

    @Test: "math"
    SubtractionTest()
      stdout <- Stdout()
      assert 10 - 3 == 7
      stdout.println("Subtraction test passed")

    // === DEMONSTRATING TEST STRUCTURE ===
    // Run all tests:       ek9 -t file.ek9
    // Run math group only: ek9 -tg math file.ek9
    // JSON output:         ek9 -t2 file.ek9
    // JUnit XML output:    ek9 -t3 file.ek9
    // With coverage:       ek9 -tC file.ek9

Common mistakes

E50060 — Integer has no intValue() method. multiply() already returns an Integer. See ek9 -h E50060 for details.

Incorrect:

result <- multiply(6, 7).intValue()

Correct:

result <- multiply(6, 7)

E50060 — Integer has no toString() method. Use the $ prefix operator for string conversion or string concatenation. See ek9 -h E50060 for details.

Incorrect:

stdout.println(result.toString())

Correct:

stdout.println("6 * 7 = " + $result)
Other ways to ask this
  • How do I run EK9 tests from the command line?
  • How do I check test coverage in EK9?
  • What test output formats does EK9 support?

Coming from another language?

Java: mvn test or gradle test with JUnit, JaCoCo for coverage. Python: pytest with pytest-cov for coverage. Rust: cargo test with tarpaulin for coverage. Go: go test -v with go test -cover. EK9: built-in ek9 -t runner with JSON/JUnit XML output formats and integrated coverage via -tC flags, no external tools needed.

Keywords: group, runner, junit, output, compile, run, assert, verify, json, results, test, format, result, coverage