I have downloaded shUnit v1.3 but being quite new to unit test frameworks of any description I cannot work out where to start and I have not been able to find any documentation on SourceForge. Can anyone out there please help me find out how to write tests and run them? I realise the test logic must be proprietary etc, but the nature of how the tests hook into the framework would be very useful.
Many thanks for your help
Adrian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am using shUnit to establish a test framework for existing code, so that code can be refactored safely. I was initially pointed to a few sites about unit testing, the wikipedia article on unit testing and tutorials on the JUnit site. These did not help too much with shUnit, but until I got my head around xUnit testing, it was very hard to think about how to write tests. Now, a few weeks later, I feel pretty comfortable with shUnit and have even written some custom asserts!
To help you get started though, below is an example function that needed a test. It is a very small function, and so I believe I can paste the function, a test function, and the "glue" to hook it into shUnit. Hopefully it will be something that you can paste into a text editor, save in the directory that contains the shUnit code, and execute!
$sh test.sh
In the test function, I tried to follow the same style for tests that is used in shUnitTest and shUnitPlusTest. These files also contain many tests that test the base functionality of shUnit and shUnitPlus to ensure the functions in shUnit and shUnitPlus work as envisioned.
Good Luck
m@
********** COPY BELOW THIS LINE ***************
# ask_for_input expects ${1} to be question to display to user
# ${2} is a default answer that will be returned
# in the variable ${ANS} if no input is supplied,
# otherwise, ${ANS} will be read from stdin
ask_for_input() {
echo -n "$1: [$2] "
read ANS
if [ "${ANS}X" = "X" ]
then
ANS=$2
fi
}
# This is the test function that will call the function to be tested,
# feed it some input, and test the output against known good values
Test_ask_for_input() {
local question="Question"
local default="Default"
local input="Input"
ask_for_input ${question} ${default} > /dev/null << EOF1 # redirect to /dev/null to keep output of shUnit "pretty"
EOF1
[ X${ANS} = X${default} ] #test that strings are equal
shuAssert "Default case ask_for_input" $?
#TestAll could be named anything, this function just has to be
# passed as the first argument ot shuStart below
TestAll() {
#This line registers the test with shUnit
shuRegTest Test_ask_for_input
}
. shUnitPlus #Could just source shUnit
shuStart TestAll #Command to start shUnit testing
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have downloaded shUnit v1.3 but being quite new to unit test frameworks of any description I cannot work out where to start and I have not been able to find any documentation on SourceForge. Can anyone out there please help me find out how to write tests and run them? I realise the test logic must be proprietary etc, but the nature of how the tests hook into the framework would be very useful.
Many thanks for your help
Adrian
Hello,
I am using shUnit to establish a test framework for existing code, so that code can be refactored safely. I was initially pointed to a few sites about unit testing, the wikipedia article on unit testing and tutorials on the JUnit site. These did not help too much with shUnit, but until I got my head around xUnit testing, it was very hard to think about how to write tests. Now, a few weeks later, I feel pretty comfortable with shUnit and have even written some custom asserts!
To help you get started though, below is an example function that needed a test. It is a very small function, and so I believe I can paste the function, a test function, and the "glue" to hook it into shUnit. Hopefully it will be something that you can paste into a text editor, save in the directory that contains the shUnit code, and execute!
$sh test.sh
In the test function, I tried to follow the same style for tests that is used in shUnitTest and shUnitPlusTest. These files also contain many tests that test the base functionality of shUnit and shUnitPlus to ensure the functions in shUnit and shUnitPlus work as envisioned.
Good Luck
m@
********** COPY BELOW THIS LINE ***************
# ask_for_input expects ${1} to be question to display to user
# ${2} is a default answer that will be returned
# in the variable ${ANS} if no input is supplied,
# otherwise, ${ANS} will be read from stdin
ask_for_input() {
echo -n "$1: [$2] "
read ANS
if [ "${ANS}X" = "X" ]
then
ANS=$2
fi
}
# This is the test function that will call the function to be tested,
# feed it some input, and test the output against known good values
Test_ask_for_input() {
local question="Question"
local default="Default"
local input="Input"
ask_for_input ${question} ${default} > /dev/null << EOF1 # redirect to /dev/null to keep output of shUnit "pretty"
EOF1
[ X${ANS} = X${default} ] #test that strings are equal
shuAssert "Default case ask_for_input" $?
ask_for_input ${question} ${default} > /dev/null << EOF2
${input}
EOF2
[ X${ANS} = X${input} ]
shuAssert "Input case ask_for_input" $?
}
#TestAll could be named anything, this function just has to be
# passed as the first argument ot shuStart below
TestAll() {
#This line registers the test with shUnit
shuRegTest Test_ask_for_input
}
. shUnitPlus #Could just source shUnit
shuStart TestAll #Command to start shUnit testing
Hi,
I lost interest in this for a while but I have recently come back. Thanks very much for your reply - it's been very useful.
Adrian