Bats-core

TAP-compliant testing framework for Bash 3.2+ that runs test cases written as Bash functions to verify Bash scripts and other UNIX programs.

Bats (Bash Automated Testing System) is a TAP-compliant testing framework for Bash 3.2 or above. It is used to verify that UNIX programs behave as expected. Bats-core is the community-maintained continuation of the original sstephenson/bats project, forked in 2017 after the original became inactive and later archived.

A Bats test file is a Bash script, run with the bats interpreter, that uses a special @test "description" { ... } syntax. Each test case is a function with a description. Test bodies are ordinary shell commands run with Bash's errexit (set -e) option. A test passes if every command exits with status 0, so each line acts as an assertion, for example [ "$result" -eq 4 ].

Bats is most useful for testing software written in Bash, but it can test any UNIX program that can be invoked from the shell. Because it emits TAP output (for example via bin/bats --tap test), results can be consumed by TAP-aware tooling and CI systems. Documentation is hosted on Read the Docs, and the wiki has a list of open-source projects that use Bats and instructions for editor syntax highlighting. Typical users are developers and DevOps engineers who write shell scripts and command-line tools.

Alternatives & related tools

add a badge to your README

Maintain Bats-core? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/bats-core.svg)](https://www.trmn.sh/tools/bats-core?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/bats-core?utm_source=badge"><img src="https://www.trmn.sh/badge/bats-core.svg" alt="Featured on trmn" height="20"></a>