{"id":13687952,"url":"https://github.com/jetify-com/nixtest","last_synced_at":"2026-03-16T21:36:15.401Z","repository":{"id":168059116,"uuid":"624096625","full_name":"jetify-com/nixtest","owner":"jetify-com","description":"A tiny unit testing framework written in pure Nix","archived":false,"fork":false,"pushed_at":"2024-04-09T20:37:30.000Z","size":14,"stargazers_count":49,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-22T20:11:45.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jetify-com.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-05T18:31:10.000Z","updated_at":"2025-03-18T16:41:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"3cd84128-7bf9-4883-bc51-23949af5d0e7","html_url":"https://github.com/jetify-com/nixtest","commit_stats":null,"previous_names":["jetpack-io/nixtest","jetify-com/nixtest"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetify-com%2Fnixtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetify-com%2Fnixtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetify-com%2Fnixtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jetify-com%2Fnixtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jetify-com","download_url":"https://codeload.github.com/jetify-com/nixtest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250316056,"owners_count":21410476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T15:01:03.916Z","updated_at":"2026-03-16T21:36:15.361Z","avatar_url":"https://github.com/jetify-com.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# NixTest\n\n### A tiny unit testing framework written in pure Nix\n\n![License: Apache 2.0](https://img.shields.io/github/license/jetify-com/nixtest)\n\n## What is it?\n\nNixTest is a simple unit testing framework for Nix, written in pure Nix.\nIt makes it easy to add tests throughout your nix code and run them all at once.\n\nThe framework was designed to be minimal: it is entirely self-contianed and\ndepends only on nix builtin functions. Specifically, it does _not_ depend on `nixpkgs`,\nwhich can get somewhat large as a dependency.\n\nNixTest was originally built by [jetify](https://www.jetify.com) – the company behind [Devbox](https://github.com/jetify-com/devbox) (one of the easiest ways to use Nix).\n\n## Usage\n\n### 1. Import the library\n\nTo use the nixtest library, import it as an input in the flake where you are\nwriting tests, and call `nixtest.run \u003cdir\u003e` on the root directory:\n\n```nix\n{\n  inputs.nixtest.url = \"github:jetify-com/nixtest\";\n  outputs = { self, nixtest }: {\n    # Will recursively look for _test.nix files in the current directory\n    # and run them:\n    tests = nixtest.run ./.;\n  };\n}\n```\n\n### 2. Write your tests\n\nTo write tests, create files ending in `_test.nix`. If you are trying to test\na file named `foo.nix`, you should name your test file `foo_test.nix`.\n\nThe test file should evaluate to a list of test results, where each result has\nthe following schema:\n\n```\n{\n  name: string  # The name of the test\n  actual: any   # The result from evaluating the expression you're trying to test\n  expected: any # The expected result\n}\n```\n\nThe test framework will automatically check that `actual == expected`, and if it\nisn't, it will throw an error indicating a failure.\n\nThis is what an example `lib_test.nix` file might look like:\n\n```nix\nlet\n  lib = import ./lib.nix;\nin [\n  {\n    name = \"Test function concatenate\";\n    actual = lib.concatenate \"a\" \"b\";\n    expected = \"ab\";\n  }\n  {\n    name = \"Test function add\";\n    actual = lib.add 1 2;\n    expected = 3;\n  }\n]\n```\n\n### 3. Run your tests\n\nUse `nix eval` to run your tests.\n\nFor example, if your flake has a `tests` attribute as in the example above,\nyou can run your tests with:\n\n```bash\nnix eval .#tests\n```\n\nIf all tests pass, you will see an output like this:\n\n```\n[PASS] 7/7 tests passed\n```\n\nIf any tests fail, you will see an output like this:\n\n```\nerror: 1/7 tests failed\n       [FAIL] Test function add\n         Got: 2\n         Expected: 3\n```\n\n## Related Work\n\n-   [runTests](https://nixos.org/manual/nixpkgs/stable/#function-library-lib.debug.runTests): A testing function included in `nixpkgs.lib.debug`. Probably the\n    most commonly used testing library for Nix. We recommend using it for cases\n    where you are ok depending on `nixpkgs`.\n-   [Nixt](https://github.com/nix-community/nixt): Unit testing framework for Nix, written\n    in Typescript. Depends on both `nixpkgs` and `typescript`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetify-com%2Fnixtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjetify-com%2Fnixtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjetify-com%2Fnixtest/lists"}