Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FAQ

What about a watch mode?

This adds a lot of additional complexity and for now is better dealt with by using external file watcher tools such as Reflex & Watchman.

Can I change the colors?

nix-unit uses difftastic, which can be configured via environment variables. You can turn off colors via DFT_COLOR=never, give difftastic a hint for choosing better colors with DFT_BACKGROUND=light or see the full list of options via e.g. nix run nixpkgs#difftastic -- --help.

How do I compare derivations?

Comparing derivations directly will deep-force a derivation and its attributes, making a naive test case like:

let
  pkgs = import <nixpkgs> {};
in {
  test-hello = {
    expr = pkgs.hello;
    expected = pkgs.hello;
  };
}

output a cryptic series of lines like:

...
evaluation warning: Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail.
evaluation warning: Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail.
evaluation warning: Use `stdenv.tests` instead. `passthru` is a `mkDerivation` detail.
error: stack overflow (possible infinite recursion)

To work around this instead compare the derivation paths:

let
  pkgs = import <nixpkgs> {};
in {
  test-hello = {
    # Compare as strings
    expr = "${pkgs.hello}";
    expected = "${pkgs.hello}";
  };
}

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.

ToolCan test eval failuresTests defined in Nixin nixpkgssnapshot testing(1)
Nix-unityesyesyesno
runTestsnoyesyesno
Nixtnoyesnono
Namakanoyesyesyes
  1. Snapshot testing