bashunit

A simple testing library for bash scripts.

Usage

Write tests files like:

# file: tests/my_test.sh

function test_using_snake_case() {
  assertEquals "1" "1"
  assertContains "Linux" "GNU/Linux"
}

function testUsingCamelCase() {
  assertNotContains "Linus" "GNU/Linux"
  assertMatches ".*Linu*" "GNU/Linux"
  assertExitCode "0"
}

Then run the test:

$ bashunit tests/my_test.sh

Running logic_test.sh
✓ Passed: UsingCamelCase
✓ Passed: Using snake case

Tests:      2 passed, 2 total
Assertions: 5 passed, 5 total
All tests passed

Published: September 11 2023

blog comments powered by Disqus