unittest2

May 7, 2026 · View on GitHub

unittest2 is a Nim library for writing automated tests. It provides a familiar syntax similar to the built-in unittest module but includes enhanced reporting, advanced execution modes, and first-class support for compile-time testing.

Key Features

  • Clean Output: Optimized for both human readability and CI pipelines.
  • Isolated Execution: Each test runs in its own procedure.
  • Strict Exceptions: Fully compatible with Nim's exception tracking system.
  • Tooling Integration: Generates JUnit-compatible XML reports for CI/CD workflows.
  • Compile-Time Tests: Run your tests in the Nim VM during compilation to verify code logic early.
  • Advanced Execution: Supports a two-phase "Collect-and-Run" model for better progress tracking and test listing.

Compatibility

unittest2 is designed to be mostly compatible with the standard library's unittest module. In many cases, you can simply replace import unittest with import unittest2 to get started.

Installing

nimble install unittest2

Or add it to your .nimble file:

requires "unittest2"

Usage

For detailed instructions and advanced patterns, see the official documentation:

You can also explore the tests and examples directories in this repository for more inspiration.

License

MIT

Credits