
Bats Testing Patterns
If you're writing shell scripts for production, you need tests, and this skill shows you how to build them with Bats. It covers the essentials like setup/teardown patterns, output assertions, and mocking external commands. The examples are practical: testing exit codes, validating file operations, stubbing curl calls, and managing test fixtures. Bats integrates cleanly with CI/CD pipelines and outputs TAP format, so your shell script tests work alongside the rest of your test suite. The fixture management and mocking patterns alone will save you hours of debugging flaky tests.
- skills.sh installs
- 11.4K
- GitHub stars
- 42.4K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add wshobson/agents --skill bats-testing-patterns --agent claude-codeInstalls into .claude/skills of the current project.
Files
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.
When to Use This Skill
- Writing unit tests for shell scripts
- Implementing test-driven development (TDD) for scripts
- Setting up automated testing in CI/CD pipelines
- Testing edge cases and error conditions
- Validating behavior across different shell environments
- Building maintainable test suites for scripts
- Creating fixtures for complex test scenarios
- Testing multiple shell dialects (bash, sh, dash)
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Testing Error Conditions
#!/usr/bin/env bats
@test "Function fails with missing file" {
run my_function "/nonexistent/file.txt"
[ "$status" -ne 0 ]
[[ "$output" == *"not found"* ]]
}
@test "Function fails with invalid input" {
run my_function ""
[ "$status" -ne 0 ]
}
Sponsors
Details
- Repository
- github.com/wshobson/agents
- Categories
- Testing & QA, DevOps & CI/CD, Documentation, Automation & Workflows, CLI & Terminal
More from wshobson/agents
All 174- Memory Forensics11.4K
- Risk Metrics Calculation11.4K
- Python Resource Management11.4K
- Binary Analysis Patterns11.4K
- Cqrs Implementation11.4K
- Workflow Patterns11.4K
- Incident Runbook Templates11.4K
- Airflow Dag Patterns11.3K
- Dbt Transformation Patterns11.3K
- Paypal Integration11.3K
- Temporal Python Testing11.3K
- Anti Reversing Techniques11.3K
- Angular Migration11.2K
- Nx Workspace Patterns11.2K
- Postmortem Writing11.2K
- Event Store Design11.2K
- Sast Configuration11.2K
- Hybrid Search Implementation11.2K
- Web3 Testing11.2K
- Distributed Tracing11.1K
- Screen Reader Testing11.1K
- Saga Orchestration11.1K
- Multi Cloud Architecture11.1K
- Spark Optimization11.1K