# 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.

Stars: 6.3k · Language: Shell · Categories: Dev Tools

- Repository: https://github.com/bats-core/bats-core
- Website: https://bats-core.readthedocs.io/
- Page: https://www.trmn.sh/tools/bats-core

## Overview

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

- [arduino-cli-interactive](https://www.trmn.sh/tools/arduino-cli-interactive.md): Interactive TUI wrapper for arduino-cli providing menu-driven Arduino development workflows (Shell, 44 stars)
- [jscpd](https://www.trmn.sh/tools/jscpd.md): Copy/paste detector for 224 source formats with a Rust engine. Also reports dead code, complexity, git-history duplication trends, and a health score. (Rust, 6.5k stars)
- [Popeye](https://www.trmn.sh/tools/popeye.md): Read-only scanner that lints live Kubernetes clusters for misconfigurations, unused resources, and over/under allocation, with console, JSON, and HTML reports. (Go, 6.5k stars)
- [harlequin](https://www.trmn.sh/tools/harlequin.md): Terminal-based SQL IDE with database adapter support for DuckDB, SQLite, PostgreSQL, MySQL and dozens of other databases (Python, 6.5k stars)
- [pastel](https://www.trmn.sh/tools/pastel.md): Command-line tool to generate, analyze, convert and manipulate colors across multiple formats and color spaces (Rust, 6.5k stars)

## Guides

- [Lint and test a shell script with ShellCheck and Bats](https://www.trmn.sh/guides/shellcheck-bats-workflow): Catch a quoting bug with ShellCheck, then add Bats tests for names containing spaces and wildcard characters.
- [Best Tools for Testing and Linting Shell Scripts](https://www.trmn.sh/best/shell-script-quality-tools): Compare ShellCheck, Bats-core, pre-commit: workflows, strengths and tradeoffs.

---

Canonical: https://www.trmn.sh/tools/bats-core
