bats-testing-patterns
Master Bash Automated Testing System (Bats) for comprehensive shell script testing. Use when writing tests for shell scripts, CI/CD pipelines, or requiring test-driven development of shell utilities.
About this skill
This skill offers in-depth guidance and proven patterns for effectively utilizing the Bash Automated Testing System (Bats) to create high-quality unit tests for shell scripts. It covers essential test structures, fixture management, assertion techniques, and best practices tailored for production-grade shell script validation. By leveraging this skill, AI agents can generate comprehensive, maintainable, and reliable tests for command-line utilities, CI/CD pipeline components, and other Bash-based applications, supporting test-driven development workflows and ensuring script integrity across various shell environments.
Best use case
Primarily used by AI agents tasked with generating, reviewing, or enhancing unit tests for shell scripts. It's crucial for implementing robust testing strategies in CI/CD pipelines, adopting test-driven development (TDD) for shell utilities, and ensuring the reliability and correctness of Bash-based applications.
Master Bash Automated Testing System (Bats) for comprehensive shell script testing. Use when writing tests for shell scripts, CI/CD pipelines, or requiring test-driven development of shell utilities.
The AI agent will generate well-structured, robust, and comprehensive Bats test files (`.bats`) that thoroughly validate the functionality of target shell scripts, adhering to established testing patterns and best practices. This leads to more reliable shell utilities and improved confidence in CI/CD deployments.
Practical example
Example input
Create a comprehensive Bats test file for the following shell script. Ensure robust error handling is tested and use appropriate fixtures for temporary files: ```bash #!/bin/bash # my_script.sh if [[ -z "$1" ]]; then echo "Error: Argument required" >&2 exit 1 fi OUTPUT_DIR="/tmp/output" mkdir -p "$OUTPUT_DIR" echo "Processed: $1" > "$OUTPUT_DIR/$(basename "$1").log" echo "Successfully processed $1" exit 0 ```
Example output
```
# test_my_script.bats
@test "my_script.sh processes argument successfully" {
local output_dir="/tmp/bats_test_output_$(uuidgen)"
setup() {
mkdir -p "$output_dir"
}
teardown() {
rm -rf "$output_dir"
}
export OUTPUT_DIR="$output_dir" # Override default for testing
run ./my_script.sh "test_file.txt"
assert_success
assert_output_contains "Successfully processed test_file.txt"
assert_file_exist "$output_dir/test_file.txt.log"
assert_file_contains "$output_dir/test_file.txt.log" "Processed: test_file.txt"
}
@test "my_script.sh exits with error if no argument is provided" {
run ./my_script.sh
assert_failure
assert_output_stderr_contains "Error: Argument required"
}
@test "my_script.sh handles arguments with special characters" {
local output_dir="/tmp/bats_test_output_$(uuidgen)"
setup() {
mkdir -p "$output_dir"
}
teardown() {
rm -rf "$output_dir"
}
export OUTPUT_DIR="$output_dir"
run ./my_script.sh "file with spaces & symbols.name"
assert_success
assert_output_contains "Successfully processed file with spaces & symbols.name"
assert_file_exist "$output_dir/file with spaces & symbols.name.log"
}
```When to use this skill
- When an AI agent needs to generate comprehensive unit tests for a given Bash shell script.
- To apply Test-Driven Development (TDD) principles when developing or modifying shell utilities.
- For setting up or enhancing automated testing phases within CI/CD pipelines that involve shell scripts.
- When validating specific edge cases, error handling, and expected behaviors of shell scripts.
When not to use this skill
- When testing applications or scripts written in languages other than Bash (e.g., Python, Node.js, Go), as Bats is specific to Bash.
- For integration or end-to-end testing that requires mocking external systems beyond typical shell interactions.
- When the primary goal is not unit testing, but rather static analysis, linting, or security scanning of shell scripts.
- If the AI agent is not equipped to generate or understand code based on provided patterns and best practices.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/bats-testing-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How bats-testing-patterns Compares
| Feature / Agent | bats-testing-patterns | Standard Approach |
|---|---|---|
| Platform Support | Claude | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | easy | N/A |
Frequently Asked Questions
What does this skill do?
Master Bash Automated Testing System (Bats) for comprehensive shell script testing. Use when writing tests for shell scripts, CI/CD pipelines, or requiring test-driven development of shell utilities.
Which AI agents support this skill?
This skill is designed for Claude.
How difficult is it to install?
The installation complexity is rated as easy. You can find the installation instructions above.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
AI Agents for Startups
Explore AI agent skills for startup validation, product research, growth experiments, documentation, and fast execution with small teams.
SKILL.md Source
# Bats Testing Patterns Comprehensive guidance for writing comprehensive unit tests for shell scripts using Bats (Bash Automated Testing System), including test patterns, fixtures, and best practices for production-grade shell testing. ## Use this skill when - Writing unit tests for shell scripts - Implementing TDD for scripts - Setting up automated testing in CI/CD pipelines - Testing edge cases and error conditions - Validating behavior across shell environments ## Do not use this skill when - The project does not use shell scripts - You need integration tests beyond shell behavior - The goal is only linting or formatting ## Instructions - Confirm shell dialects and supported environments. - Set up a test structure with helpers and fixtures. - Write tests for exit codes, output, and side effects. - Add setup/teardown and run tests in CI. - If detailed examples are required, open `resources/implementation-playbook.md`. ## Resources - `resources/implementation-playbook.md` for detailed patterns and examples.
Related Skills
n8n-expression-syntax
Validate n8n expression syntax and fix common errors. Use when writing n8n expressions, using {{}} syntax, accessing $json/$node variables, troubleshooting expression errors, or working with webhook data in workflows.
mermaid-expert
Create Mermaid diagrams for flowcharts, sequences, ERDs, and architectures. Masters syntax for all diagram types and styling.
mcp-builder-ms
Use this skill when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
makepad-deployment
CRITICAL: Use for Makepad packaging and deployment. Triggers on: deploy, package, APK, IPA, 打包, 部署, cargo-packager, cargo-makepad, WASM, Android, iOS, distribution, installer, .deb, .dmg, .nsis, GitHub Actions, CI, action, marketplace
macos-menubar-tuist-app
Build, refactor, or review SwiftUI macOS menubar apps that use Tuist.
kaizen
Guide for continuous improvement, error proofing, and standardization. Use this skill when the user wants to improve code quality, refactor, or discuss process improvements.
issues
Interact with GitHub issues - create, list, and view issues.
hugging-face-tool-builder
Your purpose is now is to create reusable command line scripts and utilities for using the Hugging Face API, allowing chaining, piping and intermediate processing where helpful. You can access the API directly, as well as use the hf command line tool.
git-pushing
Stage all changes, create a conventional commit, and push to the remote branch. Use when explicitly asks to push changes ("push this", "commit and push"), mentions saving work to remote ("save to github", "push to remote"), or completes a feature and wants to share it.
git-hooks-automation
Master Git hooks setup with Husky, lint-staged, pre-commit framework, and commitlint. Automate code quality gates, formatting, linting, and commit message enforcement before code reaches CI.
gh-review-requests
Fetch unread GitHub notifications for open PRs where review is requested from a specified team or opened by a team member. Use when asked to "find PRs I need to review", "show my review requests", "what needs my review", "fetch GitHub review requests", or "check team review queue".
fp-types-ref
Quick reference for fp-ts types. Use when user asks which type to use, needs Option/Either/Task decision help, or wants fp-ts imports.