TE

OCaml Testing

Testing conventions for OCaml using Alcotest or OUnit2

Details

Language / Topic
ocamlOCaml
Category
Testing

Rules

balanced
- Use `Alcotest` with `test_case` and `run` to define and execute tests with typed assertion functions like `Alcotest.(check string)`.
- Group related tests into `let tests = ["group", [`Quick, "description", test_fn]]` lists and pass them to `Alcotest.run`.
- Place tests in a `test/` directory as a separate `dune` library or executable — never embed test code in production modules.
- Use `Alcotest.check` with custom `testable` values for domain types — implement `pp` and `equal` for readable failure output.