Flexible
Assertions, mocks, spies, data providers and snapshots to check your scripts' output and behavior.
Write and run tests for your Bash scripts on Bash 3.0 and newer.
Assertions, mocks, spies, data providers and snapshots to check your scripts' output and behavior.
Run in parallel or shard the suite across runners, run only what changed, measure coverage, and publish JUnit, TAP, JSON, HTML or Markdown reports.
Ask questions, report bugs, suggest features and contribute on GitHub.
Run the same tests on Linux, macOS and Windows via WSL.
Install bashunit and create folders for your script and test:
curl -s https://bashunit.com/install.sh | bash
mkdir -p src testsSave these two files:
#!/usr/bin/env bash
function greet() {
printf 'Hello, %s!\n' "${1:-world}"
}#!/usr/bin/env bash
function set_up() {
source src/greet.sh
}
function test_greet_by_name() {
assert_same "Hello, Bash!" "$(greet Bash)"
}Run your test:
./lib/bashunit tests/A passing run reports:
✓ Passed: Greet by name
Tests: 1 passed, 1 total
Assertions: 1 passed, 1 totalContinue with the Quickstart for other install methods and running options.