Bats
$ bats 社区开源 低风险Bats(bats / bats-core)是遵循 TAP 规范的 Bash 脚本与 CLI 测试框架。它支持对机器解析友好的 --formatter tap 与 --formatter junit XML 报告、并行执行(--jobs)以及 --filter 用例过滤,全程无交互提示。
brew install bats-core bats 在本地直接针对本地 shell 与二进制执行 .bats 测试套件,不适用 MCP。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持确定性的非交互执行,--formatter tap、--formatter junit、--count 与 --filter 完善,但缺少原生 --json 输出。
--formatter tapemits plain TAP lines free of ANSI cursor control- Supports
--formatter junitXML reports and--countdry inspection
为每个用例提供 $BATS_TEST_TMPDIR 隔离与自动清理,但 .bats 测试本身会执行任意本地 Bash 命令。
- Automatic per-test temporary directory lifecycle (
$BATS_TEST_TMPDIR)
纯 Bash 工具,可通过 Homebrew、npm 与 Linux 发行版安装在 macOS 与 Linux(需 Bash 3.2+)。
- POSIX/Bash-only (
macos,linux), requiring WSL on Windows
Shell 脚本与 CLI 回归测试的事实标准框架,支持 --jobs 并行执行。
- Parallel test execution via
--jobs(parallel) and clean TAP output
由社区积极维护的 bats-core/bats-core 分支项目,采用 MIT 协议。
- Maintained under
bats-core/bats-core(MIT)
bats-core.readthedocs.io 文档条理清晰,完整覆盖各类格式化器、断言与参数。
- Official docs at bats-core.readthedocs.io
安全边界、鉴权与放权指南
无需身份认证;每次运行创建的临时测试目录会在测试结束后自动清理。
MIT 开源 CLI,免费使用。
# Bats (bats) Agent Rules - Pass `--formatter tap` (or `--tap`) for clean, ANSI-free output in agent logs. - Use `--count` or `--filter <regex>` before running slow integration suites.
Agent 高频安全命令配方
只读查询(安全推荐)
bats --count test/
在不执行测试主体的情况下统计匹配的 .bats 用例数量。
bats --formatter tap test/
非交互执行测试并输出无 ANSI 格式的纯 TAP-13 测试行。
受控写入与预演
bats --formatter junit --output reports/ test/
执行测试套件并将结构化的 JUnit XML 文件写入 reports/ 目录。
核心优势
- +
--formatter tap与--formatter junit可生成干净且易于 CI/Agent 解析的输出。 - +
--count与--filter <regex>支持快速筛选与统计测试用例。 - + 托管的
$BATS_TEST_TMPDIR可有效隔离各测试用例间的文件副作用。
注意事项与踩坑点
- ! 不支持原生
--json格式化器(仅支持pretty、tap、tap13与junit)。 - ! 依赖 Bash 环境(
macos/linux或 Windows WSL),且丰富断言通常需配合bats-assert等辅助库。