shunit2(1)
π NAME π
shunit2 β a whole unit test framework for shell scripts, bestie. yes fr. π
β¨ SYNOPSIS β¨
shunit2 unit-file
π DESCRIPTION π
okay so shUnit2 is an xUnit unit test framework for Bourne-based shell scripts, and it's designed to work basically the same way as JUnit, PyUnit, and all those other iconic frameworks. so if you've ever been sitting there like "omg I wish I could write a unit test for my shell script", bestieβ¦ shUnit2 can literally do the job. π«Ά
you've got two ways to run it:
- run
shunit2directly from the command line and pass it the unit file,unit-file - or directly source the
shunit2executable πΈ
and here's a lil plot twist: if you directly execute shunit2 and don't specify unit-file, shUnit2 just assumes an empty test file and returns without an error message. so likeβ¦ no drama, no screaming, it just dips. π
π OPTIONS π
ngl this part is short and I respect it:
shunit2does not support any command-line options at all. not one. zero. periodt. π
so your two moves are:
- source
shunit2with the shell's.("dot") built-in to execute your unit tests, or - directly run
shunit2as a command withunit-fileas a parameter β¨
π¦ EXAMPLE π¦
here's a lil baby script that tests whether 1 equals 1. iconic behaviour honestly:
#! /bin/sh
testEquality()
{
assertEquals 1 1
}
# load shunit2
. shunit2
the example above assumes you're running this on the machine where shunit2 is available as an executable command found in the path specified by the environment variable $PATH. π
you can alternatively copy a /usr/bin/shunit2 file from this machine to path/to/shunit2 in the target source tree and use it in the target build environment like this:
#! /bin/sh
testEquality()
{
assertEquals 1 1
}
# load shunit2
. path/to/shunit2
and here's a shell session transcript showing how to write the same test as above and execute it directly:
$ cat > test_equality.sh <<EOF
testEquality()
{
assertEquals 1 1
}
EOF
$ shunit2 test_equality.sh
β οΈ note that shunit2 is not sourced in this example. it's giving "direct execution" energy, not "dot built-in" energy. π
and if you want more sophisticated examples, they're living at file:///usr/share/doc/shunit2/examples/. go look bestie, they're right there. π
π AUTHORS π
shUnit2 was written by Kate Ward. and this man page was originally written by Ulrich Dangel. legends only, no cap. π«Ά
πΈ SEE ALSO πΈ
for more information, check out the shUnit2 GitHub project, or have a look at the installed documentation. both slay. π
and that's the whole page bestie!! this was the shunit2 page from the General Commands Manual β it's shunit2 2.1.8, dated 2020-03-29. go write some tests, you're the main character now. πβ¨π
π¦ where this page comes from
- debian bookworm: shunit2 2.1.8-3 Β· Apache-2.0
- debian trixie: shunit2 2.1.8-4 Β· Apache-2.0
- ubuntu noble: shunit2 2.1.8-4 Β· Apache-2.0
- ubuntu questing: shunit2 2.1.8-4
- ubuntu resolute: shunit2 2.1.8-4build1 Β· Apache-2.0
- ubuntu stonking: shunit2 2.1.8-4build1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms