Home

Awesome

bashunit

bashunit is a unit testing framework for Bash scripts based on xUnit principles.

This is similar to the ShUnit and its successor shUnit2.

Usage

Functions starting with 'test' will be automatically evaluated.

1. Write test cases

testEcho() {
    assertEqual "$(echo foo)" "foo"
    assertReturn "$(echo foo)" 0
}

2. Include this script at the end of your test script

source $(dirname $0)/bashunit.bash

# eof

3. Run test suite

$ ./test_example
testEcho:4:Passed
testEcho:5:Passed
Done. 2 passed. 0 failed. 0 skipped.

The return code is equal to the amount of failed testcases.

Options can be given to the test script:

$ bash ./bashunit.bash
Usage: <testscript> [options...]

Options:
  -v, --verbose  Print expected and provided values
  -s, --summary  Only print summary omitting individual test results
  -q, --quiet    Do not print anything to standard output
  -l, --lineshow  Show failing or skipped line after line number
  -f, --failed   Print only individual failed test results
  -h, --help     Show usage screen

Dependencies

API

License

bashunit is licenced under a BSD License.