wshobson avatar

Bats Testing Patterns

If you're writing shell scripts for production, you need tests, and this skill shows you how to build them with Bats. It covers the essentials like setup/teardown patterns, output assertions, and mocking external commands. The examples are practical: testing exit codes, validating file operations, stubbing curl calls, and managing test fixtures. Bats integrates cleanly with CI/CD pipelines and outputs TAP format, so your shell script tests work alongside the rest of your test suite. The fixture management and mocking patterns alone will save you hours of debugging flaky tests.

skills.sh installs
11.4K
GitHub stars
42.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add wshobson/agents --skill bats-testing-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

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.

When to Use This Skill

  • Writing unit tests for shell scripts
  • Implementing test-driven development (TDD) for scripts
  • Setting up automated testing in CI/CD pipelines
  • Testing edge cases and error conditions
  • Validating behavior across different shell environments
  • Building maintainable test suites for scripts
  • Creating fixtures for complex test scenarios
  • Testing multiple shell dialects (bash, sh, dash)

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Testing Error Conditions

#!/usr/bin/env bats

@test "Function fails with missing file" {
    run my_function "/nonexistent/file.txt"
    [ "$status" -ne 0 ]
    [[ "$output" == *"not found"* ]]
}

@test "Function fails with invalid input" {
    run my_function ""
    [ "$status" -ne 0 ]
}

Sponsors

Details

Repository
github.com/wshobson/agents
Categories
Testing & QA, DevOps & CI/CD, Documentation, Automation & Workflows, CLI & Terminal

More from wshobson/agents

All 174
1wshobson avatarweb3-testingwshobson/agentsTest smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, set11.2Kskills.sh installs
2hashicorp avatarterraform-testhashicorp/agent-skillsComprehensive guide for writing and running Terraform tests. Use when creating test files (.tftest.hcl), writing test scenarios with run blocks, validating infr9.2Kskills.sh installs
3affaan-m avatarbrowser-qaaffaan-m/eccUse this skill to automate visual testing and UI interaction verification using browser automation after deploying features.6Kskills.sh installs
4affaan-m avatarcpp-testingaffaan-m/eccUse only when writing/updating/fixing C++ tests, configuring GoogleTest/CTest, diagnosing failing or flaky tests, or adding coverage/sanitizers.5.8Kskills.sh installs
5affaan-m avatarspringboot-tddaffaan-m/eccTest-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.5.7Kskills.sh installs
6affaan-m avatarwindows-desktop-e2eaffaan-m/eccE2E testing for Windows native desktop apps (WPF, WinForms, Win32/MFC, Qt) using pywinauto and Windows UI Automation.5.7Kskills.sh installs