Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 14, 2026·3 min de lectura

Bats-Core — Bash Automated Testing System

Bats-Core is a TAP-compliant testing framework for Bash scripts, letting you write and run unit tests for shell code with familiar test syntax.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Bats-Core Overview
Comando de instalación directa
npx -y tokrepo@latest install d7e8d9e0-7f5c-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Bats-Core is the community-maintained successor to the original Bats project. It provides a simple way to verify that shell scripts and command-line programs behave as expected, using a clean syntax that extends Bash with test annotations.

What Bats-Core Does

  • Runs test files written in a Bash-compatible syntax with @test annotations
  • Outputs results in TAP (Test Anything Protocol) format for CI integration
  • Supports setup and teardown functions at both file and test level
  • Provides helper libraries for assertions, file operations, and output matching
  • Executes tests in parallel for faster feedback on large test suites

Architecture Overview

Each .bats file is preprocessed into a valid Bash script where @test blocks become functions. The Bats runner discovers test functions, executes each in a subshell for isolation, captures exit codes and output, then formats results as TAP. Helper libraries like bats-assert and bats-support are sourced into tests as needed.

Self-Hosting & Configuration

  • Install via npm, Homebrew, or by cloning the repository
  • Place test files with .bats extension in a test directory
  • Load helper libraries with bats_load_library in setup functions
  • Configure parallel execution with the --jobs flag
  • Integrate with CI by parsing TAP output or using JUnit formatters

Key Features

  • Minimal syntax that feels natural to shell script authors
  • Test isolation through subshell execution prevents side effects
  • TAP and JUnit output formats for CI pipeline compatibility
  • Extensible helper ecosystem for assertions and file checks
  • Parallel test execution for large test suites

Comparison with Similar Tools

  • ShellCheck — static analysis for shell scripts; Bats tests runtime behavior
  • shunit2 — xUnit-style shell testing; Bats uses a simpler annotation-based syntax
  • pytest — Python testing framework; Bats is purpose-built for Bash and shell scripts
  • Bash itself — manual test scripts with set -e; Bats adds structure and reporting
  • Make — task runner that can run tests; Bats provides proper test isolation and output

FAQ

Q: Can Bats test non-Bash programs? A: Yes, any command-line program can be tested since Bats runs commands and checks exit codes and output.

Q: How do I skip a test conditionally? A: Use the skip command inside a test block with an optional reason string.

Q: Does it support test fixtures? A: Yes, setup and teardown functions run before and after each test. File-level setup_file and teardown_file run once per file.

Q: Can I use it in CI/CD pipelines? A: Yes, Bats outputs TAP format by default and supports JUnit XML via the --formatter flag.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados