Running Tests
Tests can be run by running zunit
or zunit run
in your project’s root directory.
# Run all tests in the tests directory
# The following are synonymous
zunit
zunit run
Specifying Tests to Run
To run specific test files, you can pass the filename directly to ZUnit. You can run multiple files by passing a directory or glob.
# Run all tests in test_file.zunit
zunit test_file.zunit
# Run all tests in the other tests directory
# The following are synonymous
zunit other_tests
zunit other_tests/**/*.zunit
Running Individual Tests
To run a single test, use the syntax filename@'name'
.
# Run a test named 'My first test' in my_tests.zunit
zunit my_tests.zunit@'My first test'
Options
You can change the way ZUnit runs your tests by passing the following CLI options.
--fail-fast
By default, ZUnit will run all tests, and then report the full results at the end of the run. Passing the --fail-fast
option halts test execution as soon as a failure, error or warning is encountered.
This option overrides the value of fail_fast
in .zunit.yml
.
zunit --fail-fast
--allow-risky
By default, if a test does not contain any assertions, it will be marked with a warning, and the run will fail. You can disable this functionality by passing the --allow-risky
option.
This option overrides the value of allow_risky
in .zunit.yml
.
zunit --allow-risky
--tap
Passing the --tap
option will disable ZUnit’s progress spinner, and print results in a TAP compatible format.
This option overrides the value of tap
in .zunit.yml
.
zunit --tap
--time_limit
If --time-limit
is set and greater than 0
, your tests will be run within an asynchronous process, and terminated if they run for longer than the specified time.
This option overrides the value of time_limit
in .zunit.yml
.
NOTE: Due to the way child processes are handled in earlier versions of ZSH, the
time_limit
setting is ignored for ZSH versions below 5.1.0. This is necessary because in versions below 5.1.0, the exit state is never returned from the asynchronous process, which would cause tests to hang indefinitely.
# Tests will be terminated if they
# run for longer than 5 seconds
zunit --time-limit 5
--verbose
If --verbose
is set, the full output of each test is printed to stdout
zunit --verbose