dream_test/reporter/bdd
BDD-style test reporter for dream_test.
This reporter formats test results in a hierarchical, spec-like format
that mirrors your describe/it structure. It’s inspired by RSpec, Jest,
and Mocha.
Example Output
Calculator
add
✓ adds positive numbers (1ms)
✓ handles zero
subtract
✓ subtracts positive numbers
✗ handles negative results (2ms)
equal
Message: Should handle negative subtraction
Expected: -5
Actual: 5
Summary: 4 run, 1 failed, 3 passed in 3ms
Usage
import dream_test/unit.{describe, it, to_test_cases}
import dream_test/runner.{run_all}
import dream_test/reporter/bdd.{report}
import gleam/io
pub fn main() {
tests()
|> to_test_cases("my_test")
|> run_all()
|> report(io.print)
}
Status Markers
| Status | Marker | Meaning |
|---|---|---|
| Passed | ✓ | All assertions succeeded |
| Failed | ✗ | One or more assertions failed |
| Skipped | - | Test was skipped |
| Pending | ~ | Test is a placeholder |
| TimedOut | ! | Test exceeded timeout |
| SetupFailed | ⚠ | A setup hook failed |
Values
pub fn format(results: List(types.TestResult)) -> String
Format test results as a BDD-style report string.
Returns the complete report including:
- Hierarchical test results with status markers
- Failure details with messages and diffs
- Summary line with counts
Gherkin tests are automatically formatted using the Gherkin reporter style.
Use this when you need the report as a string (e.g., for testing the reporter itself or writing to a file).
Example
let report_string = format(results)
file.write("test-results.txt", report_string)
pub fn report(
results: List(types.TestResult),
write: fn(String) -> Nil,
) -> List(types.TestResult)
Print test results using a provided writer function.
This is the main entry point for most test runs. The writer function receives the formatted report string and can print it, log it, or handle it however needed.
Example
// Print to stdout
results |> report(io.print)
// Print each line separately (for flushing)
results |> report(io.println)
// Custom handling
results |> report(fn(s) { logger.info(s) })
Parameters
results- List of test results from the runnerwrite- Function that handles the formatted output string
Returns
Returns the input results unchanged, enabling pipeline composition:
to_test_cases("my_test", tests())
|> run_all()
|> report(io.print)
|> exit_on_failure()