How are you testing your nix functions? I’m writing some helper nix functions and I’d like to add some tests, but I didn’t find much about testing nix functions.
I found this project: GitHub - nix-community/nixt: Simple unit-testing for Nix [maintainer=@Lord-Valen]
It looks promising, but I don’t understand how to write a test with it
1 Like
There is a runTests function in nixpkgs/lib/debug.nix. It seems many (all?) nixpkgs/lib/tests are using that.
1 Like
thanks @bjornfor , I need to get my head around about how to run them. But the docs:
/* Evaluate a set of tests. A test is an attribute set `{expr,
expected}`, denoting an expression and its expected result. The
result is a list of failed tests, each represented as `{name,
expected, actual}`, denoting the attribute name of the failing
test and its expected and actual results.
Used for regression testing of the functions in lib; see
tests.nix for an example. Only tests having names starting with
"test" are run.
Add attr { tests = ["testName"]; } to run these tests only.
*/
runTests =
and this example:
are a good starting point
1 Like