Shellscript automated testing framework-shUnit2
Development background of shUnit2
ShUnit2 is developed based on the log4sh SHELL automated testing. It is used in a similar way as JUnit.
Preparation
1. Download shUnit2
Wget-P ~ /Download http://shunit2.googlecode.com/files/shunit2-2.1.6.tgz
2.Extract
tar -xzvf ~/download/shunit2-2.1.6.tgz
3. Execute Test Cases
~/download/shunit2-2.1.6/examples/equality_test.sh
Internal processing of test execution
The internal processing process of shUnit2 is as follows.
When shunit2 is executed, the oneTimeSetUp function, which starts with "test", is defined, the test functions listed in this function are executed as follows: if the setUp function is defined and the execution test function tearDown function is defined, the system executes the function when the oneTimeTearDown function is defined.
. "$SHUNIT2_HOME"/src/shell/shunit2
Generate Test code
Example:
#! /Bin/sh # file: test/my_function_test.sh # Read the test object... /src/my_function.shoneTimeSetUp () {:} oneTimeTearDown () {:} setUp () {:} tearDown () {:}# test case testMyFunction () {assertTrue "['myfunction 2'-eq 4]"}. "$ SHUNIT2_HOME"/src/shunit2
#!/bin/sh# file: src/my_function.shmyFunction() { echo `expr $1 \* $1`}
Reference: http://d.hatena.ne.jp/oknknic/20110823/1314113501