This is the most simple unit testing framework I could come up with. The intention here is to serve as an example of how easy it can be to get started with unit testing, even for something like bash that traditionally has less of a unit testing culture. It's heavily inspired by minunit.
#!/usr/bin/env bash
source 'minibashtest.sh'
function test_one_is_one {
assert "[ 1 -eq 1 ]" "failed to assert that 1 equals 1"
}
function test_one_is_not_two {
assert "[ 1 -neq 2 ]" "failed to assert that 1 is not 2"
}
run_test_suite
If you define functions called setup
or tear_down
, they will be called
before and after each test function respectively.
Fortunately a lot of people have given unit testing in bash some thoughts in the past. So if you want something more than just basic assertions, check thosse out: