Nargo has a built-in test runner. Any function annotated withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/noir-lang/noir/llms.txt
Use this file to discover all available pages before exploring further.
#[test] is compiled and executed as a test when you run nargo test. Tests pass if the function completes without a constraint failure, and fail otherwise.
Writing tests
Annotate a function with#[test] to mark it as a test. The function must take no arguments for a standard unit test.
#[test] function, then reports the results:
Using assert and assert_eq
Tests express expectations usingassert and assert_eq. A failing assertion causes the test to fail.
assert_eq(a, b) checks that a == b and provides a clearer failure message than assert(a == b).
Running specific tests
Pass a name substring tonargo test to run only matching tests:
"add". Use --exact to match the full name only:
Tests expected to fail
Use#[test(should_fail)] for tests that are expected to trigger a constraint failure. The test passes only if execution fails.
Matching the failure message
Useshould_fail_with to assert that the failure message contains a specific string. This lets you verify that the right assertion failed.
should_fail_with does not need to be an exact match — it only needs to be a substring of the failure message:
Unconstrained tests
Tests can callunconstrained functions directly. Marking a test function itself as unconstrained allows it to run entirely in the Brillig (unconstrained) VM, which can be useful for testing helper logic without circuit constraints.
Fuzz tests
When a#[test] function takes one or more arguments, it becomes a fuzz test. Nargo automatically generates and mutates inputs to explore the function’s behavior.
should_fail and should_fail_with:
Fuzz test options
Pass these flags tonargo test to control fuzzer behavior:
| Flag | Description |
|---|---|
--no-fuzz | Skip fuzz tests; run only argument-free tests. |
--only-fuzz | Run only fuzz tests; skip argument-free tests. |
--corpus-dir <DIR> | Load and save the fuzzer corpus from this directory. |
--minimized-corpus-dir <DIR> | Minimize the corpus and store results here instead of fuzzing. |
--fuzzing-failure-dir <DIR> | Save failing inputs to this directory. |
--fuzz-timeout <SECONDS> | Maximum time per fuzz test. Default: 1. |
--fuzz-max-executions <N> | Maximum executions per fuzz test. Default: 100000. |
--fuzz-show-progress | Print live fuzzing progress. |
--corpus-dir to persist it across runs, enabling continuous fuzzing or regression testing with previous failures.
For dedicated fuzzing sessions without the test runner, use the
nargo fuzz command, which has a standalone fuzzing harness with additional controls like --num-threads and --list-all. See the Nargo CLI reference for details.Parallel test execution
Tests run in parallel by default, using all available CPU threads. Control the thread count with--test-threads:
Output formatting
| Flag | Description |
|---|---|
--show-output | Print println output from tests to the terminal. |
-q, --quiet | Show one character per test instead of one line per test. |
--format pretty | Verbose output (default). |
--format terse | Compact one-character-per-test output. |
--format json | JSON Lines output, one object per test result. |