# Build Reliable Bats Tests for Shell Scripts

Shell scripts often lack repeatable tests for output, exit codes, files, and failures. This skill provides practical Bats patterns for maintainable local and CI test suites.

## Install

```bash
npx skillstore add sickn33/bats-testing-patterns
```

## Metadata

- Status: approved
- Slug: sickn33-bats-testing-patterns
- Skillstore revision: r2
- Version status: missing
- Tree hash: 8337f671c1d59f50cc2dd050a6780d68888248b0976e3c0a67644a7850090860
- Author: sickn33
- GitHub username: sickn33
- License: MIT
- Repository: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/bats-testing-patterns
- Ref: 5a26d1d61d694db29af9b138c661c1981076d9df
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands, network, filesystem
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/sickn33-bats-testing-patterns
- Manifest: https://skillstore.pages.dev/api/skills/sickn33-bats-testing-patterns/manifest

## Capabilities

- Structures Bats test files with setup, teardown, helpers, and fixtures.
- Creates assertions for exit codes, output, files, permissions, and error messages.
- Demonstrates function mocks, command stubs, and environment overrides.
- Designs tests for Bash, POSIX sh, and dash compatibility.
- Integrates Bats test execution with GitHub Actions and Make.

## Use Cases

- Test a shell utility: Create focused Bats tests for normal output, invalid arguments, exit codes, and file side effects.
- Add regression coverage: Convert reported shell failures into isolated fixtures and repeatable tests before changing production scripts.
- Standardize CI checks: Organize a portable Bats suite and run it consistently across supported shell environments.

## Prompt Templates

### Create a basic test

```
Write Bats tests for [script] covering successful output, one invalid argument, and expected exit codes.
```

### Test file side effects

```
Design Bats setup, teardown, and fixtures for [script]. Verify created files, contents, permissions, and cleanup.
```

### Mock external commands

```
Create Bats tests for [function] that stub [dependency]. Cover dependency success, failure, malformed output, and missing installation.
```

### Design a portable CI suite

```
Review [test suite] for Bash, sh, and dash portability. Improve fixtures, parallel safety, failure coverage, and CI execution.
```

## Limitations

- It provides guidance and examples but does not execute or validate tests.
- Examples require adaptation to the project layout, commands, and supported shells.
- It does not replace integration, security, performance, or platform-specific testing.
- Some command options differ between macOS and Linux environments.

## Best Practices

- Test one behavior per case and name the expected outcome clearly.
- Create isolated fixtures with secure temporary directories and reliable teardown.
- Cover success, failure, edge cases, and supported shell environments in CI.

## Anti Patterns

- Do not depend on live services when a controlled command stub can isolate behavior.
- Do not share writable fixture state between tests or parallel workers.
- Do not assert only output while ignoring exit codes and filesystem side effects.

## Security Audit

- Audited at: 2026-08-14T10:15:06.744\+00:00
- Summary: All 33 static findings are false positives caused by markdown examples, fixed test commands, project-relative paths, and ordinary shell redirection. No prompt injection, malicious intent, credential access, covert network activity, or unsafe executable payload was found.

## Stats

- Views: 93
- Downloads: 8
- Favorites: 0
- Popularity score: 0
