shunit2 - unit test framework for shell scripts
Contents
Description
shUnit2 is an xUnit unit test framework for Bourne-based shell scripts, and is designed to work in a
similar manner to JUnit, PyUnit, and so forth. If you have ever had the desire to write a unit test for
a shell script, shUnit2 can do the job.
You can either run shunit2 directly from the command line and specify the unit file unit-file or directly
source the shunit2 executable.
If you directly execute shunit2 and don't specify unit-file, shUnit2 assumes an empty test file and will
return without an error message.
Example
The following simple script tests whether 1 equals 1.
#!/bin/shtestEquality(){assertEquals11}#loadshunit2.shunit2
The above example assumes this is executed 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 as follows.
#!/bin/shtestEquality(){assertEquals11}#loadshunit2.path/to/shunit2
The following is a shell session transcript showing how to write the same test as above and execute it
directly.
$ cat>test_equality.sh<<EOFtestEquality(){assertEquals11}EOF
$ shunit2test_equality.sh
Note that shunit2 is not sourced in this example.
More sophisticated examples can be found in file:///usr/share/doc/shunit2/examples/.
Name
shunit2 - unit test framework for shell scripts
Options
shunit2 does not support any command-line options at all. You can either 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.
See Also
For more information, see the shUnit2 GitHub project, or have a look at the installed documentation.
shunit2 2.1.8 2020-03-29 shunit2(1)
Synopsis
shunit2unit-file
