test is the path to a Bats test file, or the path to a directory containing Bats test files.
A Bats test file is a Bash script with special syntax for defining test cases. Under the hood, each test case is just a function with a description.
Test cases consist of standard shell commands. Bats makes use of Bash´s errexit (set -e) option when running test cases. If every command in the test case exits with a 0 status code (success), the test passes. In this way, each line is an assertion of truth.
See bats(7) for more information on writing Bats tests.
You can invoke the bats interpreter with multiple test file arguments, or with a path to a directory containing multiple .bats files. Bats will run each test file individually and aggregate the results. If any test case fails, bats exits with a 1 status code.
- -c, --count
- Count the number of test cases without running any tests
- -h, --help
- Display help message
- -p, --pretty
- Show results in pretty format (default for terminals)
- -t, --tap
- Show results in TAP format
- -v, --version
- Display the version number
$ bats addition.bats ✓ addition using bc ✓ addition using dc 2 tests, 0 failures
If Bats is not connected to a terminal--in other words, if you run it from a continuous integration system or redirect its output to a file--the results are displayed in human-readable, machine-parsable TAP format. You can force TAP output from a terminal by invoking Bats with the --tap option.
$ bats --tap addition.bats 1..2 ok 1 addition using bc ok 2 addition using dc
Bats is released under the terms of an MIT-style license.