bats-testing-patterns

Write unit tests for shell scripts using the Bats testing framework.

1|Updated Jul 2, 2026
One-click install
npx skills add https://github.com/filippolmt/skills --skill bats-testing-patterns-filippolmt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bats-testing-patterns
Source: https://github.com/filippolmt/skills/tree/main/skills/bats-testing-patterns
Command: npx skills add https://github.com/filippolmt/skills --skill bats-testing-patterns-filippolmt

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Shell scripts often ship without automated tests, making regressions and edge-case failures hard to catch before they reach CI/CD pipelines or production environments. ## Core Features & Use Cases - Bats Test Patterns: Provides ready-to-use patterns for assertions on exit codes, output, files, and error conditions using the Bats framework. - Fixtures, Mocking, and Helpers: Covers setup/teardown hooks, test helper libraries, command stubbing, and fixture management for isolated tests. - CI/CD Integration: Includes GitHub Actions and Makefile configurations for running Bats suites with TAP output and parallel execution. - Use Case: When building a deployment shell script, use this Skill to generate a Bats test suite that validates success paths, failure handling, and cross-shell compatibility (bash, sh, dash) before merging. ## Quick Start Ask the AI to write a Bats test suite for your shell script, covering success cases, error handling, and cleanup with setup and teardown hooks.

Frequently Asked Questions about bats-testing-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for shell scripts with Bats?

Create a .bats file with @test blocks, use the run command to execute your script, then assert on $status for exit codes and $output for results. Add setup and teardown functions to manage temporary files and test state.

How to test shell script error handling in Bats?

Run the function with invalid input or missing files, then assert that $status is non-zero and that $output contains the expected error message. This validates both failure detection and helpful error reporting.

Can Bats test scripts across different shells like bash and dash?

Yes, invoke the script explicitly with bash, sh, or dash inside separate tests to verify portability. Use the skip command when a shell like dash is not installed on the test machine.

How do I mock external commands in Bats tests?

Create stub executables in a temporary directory and prepend it to PATH, or redefine functions and export them before running the code under test. This isolates tests from tools like curl or jq.

Does Bats integrate with CI/CD pipelines like GitHub Actions?

Yes, install Bats via npm or a package manager in your workflow, then run bats tests/*.bats. The --tap flag produces TAP output compatible with CI reporting tools, and --parallel speeds up large suites.