BST - Bash Script Tester

A simple unit-testing framework for bash.

Installation

BST is distributed with bashfun (bash function library). Installation guide here.

.test file format

Bst will run tests in the following .test file format:

#!/bin/bash

setUp() {
    # Create the test fixture: source files, define vars, etc.
    # This function will be run before each test* function is called, below.
    # A setUp function must be defined but if you don't need any setUp 
    # actions just write this:
    echo -n
}

tearDown() {
    # Do any tidying up required after the test.
    # This function will be run after each test* function is called, below.
    # A tearDown function must always be defined, but if you don't need any 
    # tearDown actions just write this:
    echo -n
}

# name all your test functions "test[Something]"
testMyFunctionReturnsTen(){
    assertEqualNumbers `myFunction` 10
}

# another example test* function
testAnotherFunctionReturnsHello() {
    assertEqualStrings `anotherFunction` 'hello'
}

#
# etc
#

assertions

These should be self-explanatory:

You can find the assertion fns in /opt/bashfun/assertions.sh

run tests

To run tests, pass the path to a directory containing .test files to bst, eg:

$ bst path/to/myapp/specifications

You can also pass as many other arguments you like and access them in test functions as numbered args $2, $3, etc. Try echoing $@ in a test function to see what's going on.

testFoo(){
    echo $@
}

If you don't see any "Fail" messages, all the tests passed.