Bats-core

github.com ↗

A TAP-compliant test framework for checking Bash scripts and command-line programs.

SI Score
80/100
Pricing
Open Source AI reading, not confirmed
Free plan
Not confirmed
Sign-up required
Not confirmed

Ask SI about Bats-core

Answers use saved listing facts and recorded sources.
Homepage screenshot
Screenshot of the Bats-core homepage

What it does

Bats-core is a test framework for Bash programs and Unix command-line tools. A test file groups shell commands under readable `@test` cases, and Bats reports which cases pass or fail using TAP-compatible output. Developers supply the script, expected exit status, and assertions about its output or effects. It fits shell utilities and deployment scripts that can be exercised in a test environment, not GUI tests or tests of application code written in another language.

Add a test beside the script

The tutorial assumes an existing project and shows adding a Bats test file such as test/test.bats. A case uses the @test form to run a shell command, then Bats reports the result; helpers such as run can capture a command's status and output for assertions. A useful first check is that a script exits successfully for valid input and returns the documented error status for invalid input. That is an example of the intended workflow, not a command executed for this record.

Bats is designed for tests that run from the shell, so it fits naturally in a local development loop or a CI job. The project describes both package-manager installation and use as a Git submodule with test libraries. Choose one install method deliberately and keep it consistent between a developer machine and CI.

The framework supports Bash 3.2 and above and is MIT-licensed. Tests still need a disposable environment for files, processes, and environment variables they change; Bats does not isolate external services or guarantee that a script is safe to run against production data.

Strengths

  • Uses shell syntax to test Bash scripts and command-line program behavior.
  • Reports results in the TAP-compatible format and can be added as a package or repository submodule.
  • The official framework is MIT-licensed.

Watch out for

  • The framework targets Bash and shell commands, so it is not a substitute for testing GUI, browser, or non-shell application behavior.
  • Tests that modify files, processes, or environment state need their own isolation and cleanup.

Best for

  • Maintainers of Bash scripts and shell-based command-line utilities
  • Operations teams testing deployment and maintenance scripts in CI
  • Developers who want readable shell tests with TAP output

Sources