ocaml-testing

Structure OCaml unit tests with Alcotest and Dune.

46|6|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/aresbit/MateBot --skill ocaml-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ocaml-testing
Source: https://github.com/aresbit/MateBot/tree/main/skills/ocaml/ocaml-testing
Command: npx skills add https://github.com/aresbit/MateBot --skill ocaml-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a structured approach to designing, implementing, and evaluating OCaml tests, helping teams improve reliability and maintainability of OCaml libraries.

Core Features & Use Cases

  • Unit test discipline: ensures each lib/.ml module has a corresponding test_.ml in test/, promoting clear coverage.
  • Deterministic testing: advocates mocks and isolated tests to keep test runs fast and repeatable.
  • Guided setup: outlines a conventional project layout (lib/, test/, dune) and how to wire Alcotest test suites with a single runner.
  • Use Case: when starting a new OCaml project, use this Skill to define test architecture, select tools (Alcotest, Dune), and plan mock strategies for IO.

Quick Start

  1. Create a project structure as shown in the example and add a simple test module, e.g., test/test_user.ml, using Alcotest.
  2. Add a dune file that runs the tests with Alcotest and run dune runtest.
  3. Iterate on tests to cover each lib/.ml module with a corresponding test_.ml file.

Frequently Asked Questions about ocaml-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure OCaml unit tests using Dune and Alcotest?

Structure OCaml tests by placing a test_*.ml file in the test/ directory for each lib/*.ml module, wiring Alcotest suites with a single runner, and executing them using dune runtest.

What is the standard project layout for deterministic OCaml testing?

A standard deterministic OCaml testing layout uses lib/ for source modules, test/ for Alcotest suites, and a dune file to configure the build and isolate tests using mocks for fast, repeatable runs.

How do I mock IO in OCaml unit tests to keep them deterministic?

Keep OCaml tests deterministic by applying mock strategies for IO within isolated test suites, ensuring fast and repeatable test runs without relying on external side effects.

Does this approach enforce 1:1 test coverage for OCaml libraries?

Yes, this approach enforces 1:1 test coverage by requiring each lib/*.ml module to have a corresponding test_*.ml file, promoting clear naming conventions and comprehensive unit test discipline.

Can I use Eio with Alcotest for OCaml testing?

Yes, you can use Eio with Alcotest when structuring OCaml tests, leveraging Eio for IO operations while applying mock strategies to build deterministic and isolated test suites.

Why should I use a single runner for Alcotest test suites?

Using a single runner for Alcotest test suites centralizes test execution, simplifies project configuration in Dune, and ensures consistent reporting across all module tests.