bats-testing-patterns
シェルスクリプトの包括的なテストのためのBash自動化テストシステム(Bats)をマスター。シェルスクリプトのテスト作成、CI/CDパイプライン、またはシェルユーティリティのテスト駆動開発が必要な場合に使用してください。
Security Assessment
Detected risks:
About bats-testing-patterns
The 'bats-testing-patterns' skill provides comprehensive guidance for creating robust unit tests for shell scripts using Bats (Bash Automated Testing System). It addresses the challenge of ensuring reliability, maintainability, and correctness in shell scripts, which are commonly used for automation, system tasks, and CI/CD pipelines. By leveraging Bats, users can implement structured testing workflows, capture output, validate exit codes, and manage setup and teardown procedures to create production-grade test suites for scripts across different environments and shell dialects.
This skill covers essential features and capabilities of Bats, including TAP-compliant testing, simple and intuitive test syntax, support for setup and teardown hooks, assertion helpers for output and exit codes, and the ability to create reusable fixtures and mock helpers. It provides practical examples of common test patterns, including command success/failure checks, output validation, multi-line handling, and file content and permission assertions. The skill also details file structure organization for test suites, demonstrating how to separate scripts, test files, fixtures, and helper utilities for maintainability and clarity.
Ideal use cases for this skill include developing unit tests for shell scripts in CI/CD environments, implementing test-driven development for shell utilities, verifying script behavior across multiple shell dialects (bash, sh, dash), and handling edge cases or error conditions. Target users are developers, DevOps engineers, and system administrators who require reliable testing solutions for shell scripts, particularly in production environments where automated validation and maintainable test patterns are crucial.
FAQ
How do I install Bats to use this skill?
You can install Bats using Homebrew on macOS with 'brew install bats-core', or on Ubuntu/Debian by cloning the bats-core repository and running './install.sh /usr/local'. It is also available globally via npm with 'npm install --global bats'. Verify installation with 'bats --version'.
Can I use this skill with different shell environments?
Yes, the skill supports testing across multiple shell dialects, including bash, sh, and dash, allowing you to verify that scripts behave consistently in different environments.
Does this skill support CI/CD integration?
Yes, Bats provides TAP-compliant output that can be integrated into CI/CD pipelines, enabling automated test execution and reporting.
What types of assertions are available with Bats?
Bats supports assertions for command exit codes, output content (including multi-line and pattern matching), and file properties such as existence, readability, permissions, and size.
Are there setup and teardown capabilities for tests?
Yes, Bats allows you to define setup and teardown functions that run before and after each test, which is useful for creating temporary directories, sourcing scripts, and cleaning up test artifacts.
Install bats-testing-patterns
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
amurata/cc-tools