Skip to content

Guide · Agent skill

How to use the Bats Shell Testing Patterns agent skill

Updated · written with AI from the project's own documentation and checked against our catalogue data

The Bats Shell Testing Patterns skill (bats-testing-patterns) gives an AI agent guidance for writing automated tests for Bash and other shell scripts using Bats, the Bash Automated Testing System. It is aimed at developers who maintain shell scripts and want a test suite, and at teams adding those tests to a CI/CD pipeline. After this guide you will know how to install the skill, how to ask for it, and what it needs to run.

Bats Shell Testing Patternswshobson/agents · MIT

Quick start

  1. 1Download and unzip the skill. Download the ZIP from this page and unzip it so you have a bats-testing-patterns folder containing SKILL.md.
  2. 2Place the folder. Move it to ~/.claude/skills/ for personal use, or to .claude/skills/ in a project. Alternatively, upload it in the Claude apps under Settings, Capabilities, Skills.
  3. 3Install Bats. Install bats-core with Homebrew, from source, or with npm, then confirm with bats --version.
  4. 4Ask for tests in plain language. Name the script you want tested and what should be covered, such as error cases or compatibility.
  5. 5Review the generated tests. Read each @test block and check it matches what your script is supposed to do before you rely on it.
  6. 6Run the suite. Run bats tests/*.bats locally, then add the same command to your CI workflow or Makefile.

What the skill makes the agent do

An agent skill is a folder of instructions that an AI agent loads when a task matches its description. This one covers writing Bats test files for shell scripts. The agent can produce tests for error cases, skip tests when a required tool is missing, check that a script behaves the same under bash, sh and dash, set up helper functions, and wire the tests into CI pipelines such as GitHub Actions or a Makefile.

  • Error-condition tests, such as missing files, invalid input and permission problems
  • Skipping tests when a tool like jq is not installed
  • Compatibility checks across bash, sh (POSIX) and dash
  • A test_helper.sh pattern with assertion and temporary directory helpers
  • Parallel execution and CI examples

Install the skill

Download the ZIP for this skill from this page and unzip it. To make it available for your user account, place the folder in ~/.claude/skills/. To limit it to one project, place it in that project's .claude/skills/ folder.

You can also upload the skill in the Claude apps: open Settings, go to Capabilities, then Skills, and upload it there.

  • Personal: ~/.claude/skills/
  • Single project: .claude/skills/ inside the project

Install Bats so the tests can run

The skill writes tests, but Bats must be installed on your machine to run them. The skill's reference file lists three options. Pick whichever fits your system.

  • macOS with Homebrew: brew install bats-core
  • Ubuntu/Debian: clone bats-core from GitHub and run ./install.sh /usr/local
  • Any system with Node.js: npm install --global bats
bats --version

Trigger the skill with a natural request

You do not need a special command. Describe the task in plain language that matches the skill's purpose, such as writing tests for a shell script, adding tests to CI, or practising test-driven development on a command-line tool. Mention the script path so the agent knows what to test.

  • "Write Bats tests for bin/deploy.sh, including the missing-argument error case."
  • "Add a GitHub Actions job that runs my Bats tests on every push."
  • "Make my backup script's tests pass under sh and dash as well as bash."
  • "Set up a Makefile target that runs the Bats suite in TAP format."

Follow the standard test layout

The skill suggests keeping scripts in bin/ and tests in tests/, with *.bats files, a test_helper.sh file, and optional fixtures/ and helpers/ folders. A basic test uses the run command to capture the exit status and output, then checks them.

Tests can use setup() to check for required tools and skip when they are missing. The skill recommends keeping each test focused on one behaviour and using descriptive test names.

  • Use run to capture $status and $output
  • Use skip when an optional tool is absent
  • Clean up temporary files in teardown
bats tests/*.bats

Run the tests in CI or a Makefile

The skill includes a GitHub Actions workflow that installs Bats with npm, runs the test files and writes TAP output. It also includes Makefile targets for normal, verbose, TAP and parallel runs. The parallel example uses --parallel 4.

  • GitHub Actions: installs Bats with npm install --global bats
  • Makefile: test, test-verbose, test-tap and test-parallel targets
make test

What people use it for

  • Adding error-path tests to a deployment or backup script
  • Setting up a GitHub Actions job that runs Bats on each push and pull request
  • Checking that a utility works under bash, sh and dash
  • Building a Makefile test target with TAP output for other tools to read
  • Practising test-driven development on a new command-line utility

Frequently asked questions

Is the Bats Shell Testing Patterns skill free?

The skill is published under the MIT licence. Bats itself is a separate testing framework that you install on your own machine.

What do I need to use this skill?

You need an agent that supports skills, Bats installed to run the tests, and Bash plus a POSIX shell for the examples. jq is optional and only used in one example. npm is used in the CI example to install Bats.

How do I install the bats-testing-patterns skill?

Download the ZIP from this page and unzip it into ~/.claude/skills/ for personal use or a project's .claude/skills/ folder. You can also upload it in the Claude apps under Settings, Capabilities, Skills.

Does the skill run my scripts or use the network?

According to the listing, the skill does not run scripts and does not use the network. It is a reference of patterns and examples, so Bats must be installed separately to run any tests.

Can this skill test Python or JavaScript code?

No. The skill covers only shell scripts with Bats. For application code in other languages, use a testing framework built for that language.

How does this compare with writing Bats tests without a skill?

The skill supplies ready patterns for error handling, dependency skipping, shell compatibility, helpers and CI setup. You still need to check the output against your own script, since the skill is a reference rather than a tool that runs tests for you.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Choose this skill if you maintain Bash or POSIX shell scripts and want consistent Bats tests, CI examples and helper patterns to start from. Skip it if you need to test application code in another language, or if you do not have a shell script to test, since the content assumes familiarity with Bash and CI systems.

Download the skill