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.
By wshobson · 9,571 installs
npx skills add wshobson/agents --skill bats-testing-patterns
Source repository · Upstream listing
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
Testing with Dependencies
Testing Shell Compatibility
Parallel Execution
Test Helper Pattern
test helper.sh
Integration with CI/CD
GitHub Actions Workflow
Makefile Integration
Best Practices
1. Test one thing per test Single responsibility principle
2. Use descriptive test names Clearly states what is being tested
3. Clean up after tests Always remove temporary files in teardown
4. Test both success and failure paths Don't just test happy path
5. Mock external dependencies Isolate unit under test
6. Use fixtures for complex data Makes tests more readable
7. Run tests in CI/CD Catch regressions early
8. Test across shell dialects Ensure portability
9. Keep tests fast Run in parallel when possible
10. Document complex test setup Explain unusual patterns