Stacks

Write Unit Tests for Untested Code in OCaml with Atlas in 2026

Updated 7 min read

Atlas helps OCaml developers in 2026 write unit tests for untested code by reading your module, copying existing test conventions, and then using `dune runtest` to validate the new tests, ensuring full integration with your `opam` and `ocamlformat` setup.

How Atlas identifies untested OCaml code and existing conventions

Atlas in 2026 begins by thoroughly understanding your OCaml project. It uses its `read` tool to parse the target module and the `lsp` tool's `documentSymbol` operation to enumerate all exported symbols, ensuring no public function is missed. This initial scan helps Atlas identify exactly what needs testing.

Atlas's first step in writing unit tests for untested OCaml code involves a deep analysis of the codebase. It leverages its `read` tool to ingest the contents of the module under test, understanding its structure and logic. Crucially, Atlas then employs the `lsp` tool with its `documentSymbol` operation to precisely enumerate every exported symbol within that module. This ensures that every public function, type, or value that needs testing is accounted for, preventing gaps in test coverage. To maintain consistency with the repository's existing testing practices, Atlas uses its `grep` tool to search for an existing test file. This allows Atlas to identify and adopt the project's specific framework, import style, and naming conventions, such as how `Alcotest` cases are typically structured within a `test/dune` stanza. This approach guarantees that any new tests written by Atlas will direct integrate into the project's established OCaml testing ecosystem, making them immediately familiar and maintainable for other developers.

Writing OCaml unit tests with Atlas and dune runtest

After understanding the OCaml module and its conventions, Atlas in 2026 drafts the new test spec file. It uses the `write` tool to generate the test code, which might include adding an `Alcotest` case to an existing `test/dune` stanza, and then immediately runs `dune runtest` to execute the new suite.

Once Atlas has a clear understanding of the OCaml module and the project's testing conventions, it proceeds to write the new unit test specification. The `write` tool is central to this process, generating the necessary OCaml code for the tests. This often involves creating a new `.ml` test file or extending an existing one, incorporating `Alcotest` cases as appropriate for the `test/dune` stanza. A core principle of Atlas's workflow is that a test is not a test until it has been executed. Therefore, immediately after writing the test code, Atlas uses the `bash` tool to invoke `dune runtest`. This command executes the entire test suite, including the newly added tests. Atlas then reads the output, specifically looking for failures or compiler errors. If the output exceeds 2000 lines or 50 KB, Atlas truncates it for display but saves the full log to a file for detailed review. This immediate execution and feedback loop is critical for an iterative development process, allowing Atlas to identify and address issues promptly.

Iterative refinement and OCaml code quality with Atlas

Atlas in 2026 refines OCaml unit tests iteratively, using the `edit` tool to correct failures reported by `dune runtest`. For large modules, it maintains progress with a `todowrite` list, ensuring all public functions receive comprehensive test coverage before `ocamlformat` cleans the final diff.

The process of writing unit tests with Atlas for OCaml code is inherently iterative. After `dune runtest` provides feedback, Atlas uses its `edit` tool to make necessary corrections and improvements to the test code. This cycle of writing, running, and editing continues until the entire test suite is "green," indicating all tests pass successfully. For particularly large OCaml modules, Atlas can manage the testing effort by maintaining a `todowrite` list. This feature helps track which public functions have received test coverage and which still require attention, ensuring that no part of the module remains untested. Throughout this iterative process, Atlas prioritizes code quality and consistency. Before presenting the final changes for approval, Atlas ensures that the generated and modified OCaml code adheres to the project's formatting standards by automatically running `ocamlformat`. This step guarantees that the unified diff presented for approval is not only functionally correct but also style-clean, minimizing friction during code review and maintaining a consistent codebase. Atlas also snapshots file changes as git patches, allowing edits to be easily diffed and rolled back if needed.

Atlas's safety and review mechanisms for OCaml changes

Atlas in 2026 incorporates robust safety and review mechanisms for OCaml code changes. Every Atlas tool call is permission-gated, and it drafts a plan in a read-only agent before switching to a build agent, ensuring explicit user approval for all actions, including `dune` modifications.

Atlas is designed with multiple layers of safety and user control, particularly important when modifying OCaml codebases. Every tool call made by Atlas, whether it's `read`, `write`, `bash` for `dune runtest`, or `edit`, is permission-gated against `allow`, `ask`, and `deny` rules. This means users have explicit control over what Atlas can do. Before making any changes, Atlas drafts a comprehensive plan in a read-only plan agent. This plan outlines the steps Atlas intends to take, such as adding an `Alcotest` case to a `test/dune` stanza or modifying an `.ml` file. Only after user approval does Atlas switch to a build agent to execute the plan. Furthermore, Atlas computes a unified diff for every file edit, including changes to `dune` files or OCaml source code, and surfaces it for approval before anything is written to disk. This allows OCaml developers to review the exact changes Atlas proposes, ensuring accuracy and preventing unintended modifications. Atlas also reads `git` branches, status, and diffs, and can stage and create commits on your behalf, providing a complete and transparent workflow for integrating new OCaml unit tests.

Step by step

  1. 01Use `atlas read` to analyze the OCaml module requiring tests, then `atlas lsp documentSymbol` to enumerate its public functions.
  2. 02Employ `atlas grep` to locate an existing OCaml test file, identifying the project's `Alcotest` framework, import style, and `dune` stanza conventions.
  3. 03Draft the new OCaml test spec file using `atlas write`, which will display a unified diff for approval before creating or modifying `.ml` files or `dune` stanzas.
  4. 04Execute the newly written OCaml tests with `atlas bash "dune runtest"`, allowing Atlas to read compiler errors and test failures directly from the output.
  5. 05Iterate on test code using `atlas edit` to resolve failures, potentially managing progress for large OCaml modules with `atlas todowrite`.
  6. 06Before final approval, instruct Atlas to run `atlas bash "ocamlformat <file.ml>"`, ensuring the OCaml code adheres to formatting standards and the diff is clean.
  7. 07Review the final unified diff presented by Atlas and approve the changes to integrate the new OCaml unit tests into your codebase.

Frequently asked questions

How does Atlas ensure new OCaml tests match my project's style?
Atlas uses its `grep` tool to find existing OCaml test files in your repository. It then analyzes these files to understand your project's specific `Alcotest` framework, import style, and naming conventions, ensuring new tests written with the `write` tool direct integrate.
Can Atlas run `dune runtest` for me in an OCaml project?
Yes, Atlas uses its `bash` tool to execute `dune runtest` directly within your OCaml workspace. It reads the output, including compiler errors and test failures, to inform its iterative test writing process.
What OCaml tools does Atlas integrate with for testing?
Atlas integrates directly with the standard OCaml toolchain, including `dune runtest` for executing tests, `opam` for package management context, and `ocamlformat` for maintaining code style.
How does Atlas handle large OCaml modules with many untested functions?
For large OCaml modules, Atlas can use its `todowrite` tool to maintain a list of functions that still require tests. This helps manage progress and ensures comprehensive coverage for all public symbols identified by `lsp documentSymbol`.
How does Atlas ensure I approve OCaml code changes before they are applied?
Atlas operates with permission-gated tool calls. It drafts a plan in a read-only agent and computes a unified diff for every proposed OCaml file edit, including `dune` stanzas. You must explicitly approve these changes before Atlas writes anything to disk.
Does Atlas understand OCaml interface files (`.mli`)?
Yes, Atlas is designed to work with OCaml's specific features. It reads your `.mli` signatures and uses the `lsp` tool's `documentSymbol` operation to accurately enumerate exported symbols, ensuring it understands the public API of your OCaml modules.
Can Atlas help add an `Alcotest` case to my `dune` file?
Yes, Atlas can modify `dune` stanzas. When writing new OCaml tests, it can add an `Alcotest` case to the appropriate `test/dune` stanza, ensuring your new tests are correctly integrated into the build system.

Try Atlas in your terminal

The terminal-native AI coding agent. Free core, single binary.

Install Atlas

Related guides

Write Unit Tests for Untested Code with Atlas in 2026

How to write unit tests for untested code with Atlas in 2026: the lsp tool enumerates exported symbols, grep copies repo conventions, and bash actually runs the suite.

Atlas for OCaml: A Terminal-Native AI Coding Agent for dune and opam Projects in 2026

Atlas is a terminal-native AI coding agent for OCaml in 2026. It reads dune stanzas and .mli signatures, runs dune runtest behind a prompt, and finishes with ocamlformat.

Upgrade an OCaml Dependency and Fix Breakage with Atlas in 2026

In 2026, OCaml developers use Atlas to upgrade dependencies like opam packages to new major versions. Atlas automates fixing compile and test failures, integrating with dune, ocamlformat, and .mli files for a

Review a pull request in OCaml with Atlas in 2026

In 2026, Atlas helps OCaml developers review pull requests by fetching diffs, reading full files, checking .mli signatures, running dune runtest, and applying ocamlformat.

Document an OCaml Module with a README using Atlas in 2026

Generate accurate, up-to-date README documentation for your OCaml modules in 2026 using Atlas. Leverage dune, opam, and ocamlformat for precise, traceable docs.

Self-review Your OCaml Working Diff Before Committing with Atlas in 2026

OCaml developers in 2026 can self-review uncommitted diffs with Atlas, catching mistakes before CI. Leverage dune runtest, ocamlformat, and opam for a clean codebase.

Onboard to an Unfamiliar OCaml Codebase with Atlas in 2026

Quickly build a working mental model of any OCaml repository in 2026 using Atlas. Leverage `dune` build rules, `opam` switches, and `.mli` interface files for rapid understanding and safe code exploration.

Automate GitHub Issue and Pull Request Triage in OCaml with Atlas in 2026

Automate GitHub issue and pull request triage for OCaml projects in 2026 using Atlas. Ensure safe, permission-gated responses from trusted users, integrating with `dune` and `opam`.

Browse this resource hub