Fr 18. Sep 14:14:13 CEST 2009

Unit testing for shell scripts with shunit2

Recently I stumbled upon a bug of an funtion in a shellscript and wanted to make sure that this bug never happens again. So i searched around and found shunit2 a nice xUnit based test framework for shell scripts.

If you ever had thought about writing unit tests for your shell scripts, do it! Its really easy, and shunit2 also supports zsh
Example test sript:

#! /bin/sh
testEquality()
{
  assertEquals 1 1
}

. shunit2

For more examples have a look at the tests for grml-autoconfig or at the example directory of the shunit2 package

Posted by Ulrich Dangel | Permanent Link