bats-testing-patterns
它能做什么
这个工具可以帮你为 Shell 脚本编写自动化测试。它会检查脚本的输出、错误和其他行为,确保脚本按预期工作。
适用场景
- ✓当你为自己编写的脚本编写测试时。
- ✓当你想确保脚本在各种场景下都能正常工作时。
- ✓当你想在持续集成(CI/CD)流程中自动验证脚本时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/bats-testing-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何编写一个测试,来检查我的备份脚本是否正确保存了文件?”
每周 5 个新技能,1 分钟读完。
工作原理
这个工具使用一个名为 Bats 的系统来编写和运行测试。它会检查脚本是否返回预期的错误码、是否输出正确的内容,以及是否执行了预期的操作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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.mdfor detailed patterns and examples.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题
什么是“Shell 脚本”?
Shell 脚本是直接在电脑终端中运行的小程序,用来自动化执行任务。
什么是 CI/CD?
这是一种将软件开发和交付流程自动化的方式,其中测试会自动运行。
什么是“单元测试”?
单元测试是把程序中的一小部分(比如一个函数或一个脚本)单独拿出来检查,以确保它能正确工作。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 48k
- 排名
- #4018
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。