unitest
A Gleam test runner with random ordering, tagging, and CLI filtering. It is a drop-in replacement for gleeunit if you’re already using asserts.
Installation
gleam remove gleeunit
gleam add unitest --dev
gleam clean
- Open
test/project_test.gleamand replaceimport gleeunitwithimport unitestandgleeunit.main()withunitest.main().
Quick Start
Create test/yourapp_test.gleam:
import unitest
pub fn main() {
unitest.main()
}
pub fn addition_test() {
assert 1 + 1 == 2
}
Run with gleam test.
Features
- Random test ordering with reproducible seeds
- Test tagging for categorization and filtering
- CLI filtering by file path, line number, test name, or tag
- Streaming output:
.pass,Ffail,Sskip
Future Work?
- Parallel execution
- Wildcard filtering
- Smarter tag discovery
CLI Usage
gleam test # Random order
gleam test -- --seed 123 # Reproducible order
gleam test -- test/my_mod_test.gleam # All tests in file
gleam test -- test/my_mod_test.gleam:42 # Test at line 42
gleam test -- --test my_mod_test.fn # Single test by name
gleam test -- --tag slow # Tests with tag
gleam test -- test/foo_test.gleam --tag slow # Combine file + tag
The positional file argument supports partial matching, so my_mod_test.gleam will match test/my_mod_test.gleam.
Tagging Tests
Mark tests for selective execution:
import unitest
pub fn slow_test() {
use <- unitest.tag("slow")
// slow test code
}
pub fn integration_db_test() {
use <- unitest.tags(["integration", "database"])
// integration test code
}
Ignoring Tags by Default
Skip certain tags unless explicitly requested:
import unitest.{Options}
pub fn main() {
unitest.run(Options(..unitest.default_options(), ignored_tags: ["slow"]))
}
Tests tagged “slow” will show as S (skipped).
Override with gleam test -- --tag slow.
Examples
See examples/demo/ for a complete working project.
Further documentation at hexdocs.pm/unitest.