Bats Testing Patterns
Test shell utilities with isolated fixtures, captured command output and explicit exit-status checks.
npx skills add wshobson/agents@bats-testing-patterns What it does
A shell utility can print a helpful error and still return success to its caller. Bats Testing Patterns makes the output, exit code and filesystem effects observable in the same test.
What changes after install
- Create per-test fixtures with setup and teardown.
- Capture command status and output using the Bats runner.
- Replace selected external commands with controlled test doubles.
Install
Run this command with Node.js 22.20 or later and select your agent in the Skills CLI.
npx skills add wshobson/agents@bats-testing-patterns Before using Bats Testing Patterns
- Bash, the Bats runner, the shell utility under test and writable temporary storage.
Read the reviewed setup instructions for the selected workflow.
When to use it
- Cover invalid arguments and missing inputs in a CLI.
- Test a shell script that writes files or calls another command.
When not to use it
- Exercising a Windows-only PowerShell command through Bash fixtures.
A worked example
For a file-copy wrapper, build a fixture containing a path with a space. Test one valid source and one missing source. Check the resulting bytes on success and verify that the failed run leaves the destination untouched.
Troubleshooting
- If cases pass only in sequence, create a fresh working directory per test.
- If a command double is ignored, inspect the test PATH.
- If a failure prints the expected message, also check that its exit status is nonzero.
How it chooses an approach
Use a fixture for a filesystem boundary and a small command double for an external executable. Run a separate compatibility case with the intended interpreter when shell dialect matters.
When to use another skill
- Test-Driven Development for choosing failure cases first.
- Systematic Debugging for isolating a shell regression.
- GitHub Release for preparing a release after CI passes.
What to check after it runs
Run the file twice and inspect both the Bats results and the temporary outputs. A second run should start with the same inputs as the first.
Related workflows
More in Testing
- Test-Driven Development — test-first implementation
- Systematic Debugging — root cause analysis
- Webapp Testing — browser interaction tests
- Verify Before Completion — verify completion claims
- Java JUnit — Java unit tests
Related skills in other categories
FAQ
- Which path should I install when a loader expects a skill directory?
- For a manual setup, select the directory containing SKILL.md. With the Skills CLI, the command above selects bats-testing-patterns by name.
- Is checking output enough for an error case?
- Check the process status too. A calling script can interpret a zero exit code as success even when the output describes a failure.