Linux command
bats 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run
bats [test.bats]
Run
bats [tests/]
Tap output
bats --tap [test.bats]
Pretty
bats --pretty [test.bats]
Filter
bats --filter ["pattern"] [test.bats]
说明
bats (Bash Automated Testing System) is a TAP-compliant testing framework for Bash scripts. It provides a simple syntax for writing tests and executing them with readable output. The tool enables test-driven development and continuous integration for shell scripts.
参数
- -c, --count
- Count tests without running
- -f, --filter _pattern_
- Filter tests by name pattern
- -t, --tap
- Output in TAP format
- -p, --pretty
- Pretty print output
- -r, --recursive
- Run tests recursively
- -j, --jobs _num_
- Number of parallel jobs (requires GNU parallel)
- -F, --formatter _name_
- Output formatter (pretty, tap, tap13, junit)
- -T, --timing
- Add timing information to tests
- -x, --trace
- Print test commands as they are executed (like set -x)
- --filter-tags _tags_
- Only run tests matching all comma-separated tags
- --filter-status _status_
- Run tests by status from last run (failed, missed)
- -o, --output _dir_
- Directory to write report files
- --no-tempdir-cleanup
- Preserve test output temporary directory
- --print-output-on-failure
- Automatically print $output on failed tests
- -v, --version
- Display version number
FAQ
What is the bats command used for?
bats (Bash Automated Testing System) is a TAP-compliant testing framework for Bash scripts. It provides a simple syntax for writing tests and executing them with readable output. The tool enables test-driven development and continuous integration for shell scripts.
How do I run a basic bats example?
Run `bats [test.bats]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c, --count do in bats?
Count tests without running