Unit testing for Nix code [maintainer=@adisbladis] https://nix-community.github.io/nix-unit/
Find a file
Jörg Thalheim 1c9ab50554
Merge pull request #274 from mightyiam/runCommand
runCommandNoCC -> runCommand
2025-11-10 12:29:46 +01:00
.github Revert "switch to buildbot" 2025-11-10 21:42:45 +13:00
dev reformat with nixfmt 2024-11-09 07:40:00 +01:00
doc doc: Flake-parts integration 2024-12-04 00:02:22 +01:00
lib Merge pull request #274 from mightyiam/runCommand 2025-11-10 12:29:46 +01:00
src treewide: format 2025-11-10 22:52:09 +13:00
templates runCommandNoCC -> runCommand 2025-11-05 20:59:50 +07:00
tests Fix failing properly on missing error 2025-11-10 22:50:37 +13:00
.clang-format Move clang-format config to .clang-format 2023-07-14 07:09:40 +00:00
.envrc Revert "switch to buildbot" 2025-11-10 21:42:45 +13:00
.gitignore Add editorconfig-checker 2021-08-25 13:58:43 -05:00
.nix-version bump version 2023-03-10 09:09:44 +01:00
default.nix switch to nixComponents 2025-08-12 09:45:51 +02:00
flake.lock Revert "switch to buildbot" 2025-11-10 21:42:45 +13:00
flake.nix Revert "switch to buildbot" 2025-11-10 21:42:45 +13:00
LICENSE.md Add editorconfig-checker 2021-08-25 13:58:43 -05:00
meson.build update to Nix 2.24 2024-11-11 01:43:58 +00:00
README.md README: Add lix-unit to comparison table, note on compatibility and fork reasoning 2024-10-08 00:50:22 +00:00
renovate.json Add renovate.json 2023-10-31 19:58:17 +13:00

nix-unit

This project runs an attribute set of tests compatible with lib.debug.runTests while allowing individual attributes to fail.

Why use nix-unit?

  • Simple structure compatible with lib.debug.runTests

  • Allows individual test attributes to fail individually.

Rather than evaluating the entire test suite in one go, serialise & compare nix-unit uses the Nix evaluator C++ API. Meaning that we can catch test failures individually, even if the failure is caused by an evaluation error.

  • Fast.

No additional processing and coordination overhead caused by the external process approach.

Comparison with other tools

This comparison matrix was originally taken from Unit test your Nix code but has been adapted. Pythonix is excluded as it's unmaintained.

Tool Can test eval failures Tests defined in Nix in nixpkgs snapshot testing(1) Supports Lix
Nix-unit yes yes yes no no
Lix-unit yes yes no no yes (2)
runTests no yes yes no yes
Nixt no yes no no yes
Namaka no yes yes yes ?
  1. Snapshot testing
  2. While lix-unit supports Lix, it does not support Nix, and vice versa.

Using with Lix instead of Nix

The Lix codebase has gone through significant changes, and it's not tenable to have a single code base that supports both implementations. Therefore nix-unit has been forked into lix-unit

Documentation

https://nix-community.github.io/nix-unit/