shunit2(1)

πŸ“¦
version 2.1.8 Β· 2 versions
  • 2.1.8 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 2.1.6 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸŽ€ 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 shunit2 directly from the command line and pass it the unit file, unit-file
  • or directly source the shunit2 executable 🌸

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:

  • shunit2 does not support any command-line options at all. not one. zero. periodt. πŸ™ˆ

so your two moves are:

  • source shunit2 with the shell's . ("dot") built-in to execute your unit tests, or
  • directly run shunit2 as a command with unit-file as 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