Change:
We have documentation on how to write NixOS (module) tests. But how to write tests for packages? I asked on IRC and got some helpful informations: So my goal with this issue is to get this information documented. explain the difference between NixOS module tests and package tests explain when to use which link to good examples for both create one example for a module test with nginx to test a package that needs internet access to download stuff We maybe have to decide on a policy when a test should be and when not (e.g. it's not important enough to use costly module tests) Related issues:
There is also to link to test derivations from a package. It should be called initially, but it's not possible due to technical limitations.
commented in So this looks like the way to go for now!
Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly: for maintainers and people that previously touched the related code and @ mention them in a comment. on the . 3. Ask on the on .
i still want to do it waiting for markdown docs
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
This issue has been mentioned on NixOS Discourse. There might be relevant details there:

Discussion:
```ShellSession $ git diff > nixpkgs/pkgs/the/package/0001-changes.patch ``` <ins> ## Package tests {#sec-package-tests} Tests are important to ensure quality and make reviews and automatic updates easy. Nix package tests are a lightweight alternative to [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). They can be used to create simple integration tests for packages while the module tests are used to test services or programs with a graphical user interface on a NixOS VM. Unittests that are included in the source code of a package should be executed in the `checkPhase`. ### Writing package tests {#ssec-package-tests-writing} This is an example using the `phoronix-test-suite` package with the current best practices. Add the tests in `passthru.tests` to the package definition like this: ```nix { stdenv, lib, fetchurl, callPackage }: stdenv.mkDerivation { … passthru.tests = { simple-execution = callPackage ./tests.nix { }; }; meta = { … }; } ``` Create `tests.nix` in the package directory: ```nix { runCommand, phoronix-test-suite }: let inherit (phoronix-test-suite) pname version; in runCommand "${pname}-tests" { meta.timeout = 3; } '' # automatic initial setup to prevent interactive questions ${phoronix-test-suite}/bin/phoronix-test-suite enterprise-setup >/dev/null # get version of installed program and compare with package version if [[ `${phoronix-test-suite}/bin/phoronix-test-suite version` != *"${version}"*  ]]; then echo "Error: program version does not match package version" exit 1 fi # run dummy command ${phoronix-test-suite}/bin/phoronix-test-suite dummy_module.dummy-command >/dev/null # needed for Nix to register the command as successful touch $out '' ``` ### Running package tests {#ssec-package-tests-running} You can run these tests with: ```ShellSession $ cd path/to/nixpkgs $ nix-build -A phoronix-test-suite.tests ``` ### Examples of package tests {#ssec-package-tests-examples} Here are examples of package tests: - [Jasmin compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/jasmin/test-assemble-hello-world/default.nix) - [Lobster compile test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/lobster/test-can-run-hello-world.nix) - [Spacy annotation test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/spacy/annotation-test/default.nix) - [Libtorch test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/libtorch/test/default.nix) - [Multiple tests for nanopb](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/nanopb/default.nix) </ins>