Shell script automated testing framework, shellscript
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.
- Shunit2 will list the test functions starting with "test" during execution.
- When the oneTimeSetUp function is defined, it is executed.
- The listed test functions are executed as follows:
- If the setUp function is defined, execute the function.
- Execute the test function
- When the tearDown function is defined, it is executed.
- When the oneTimeTearDown function is defined, it is executed.
. "$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
Write a SHELL Script according to the following content
#! /Bin/ksh
While [1]
Do
Echo "Please enter a filename: \ c"
Read filename
If [-z "$ {filename}"]; then
Continue
Elif [-f "'pwd'/$ {filename}"]; then
More $ {filename}
Break
Fi
Done
What are the automated testing frameworks?
The automated testing framework can be selected based on project requirements.
1. modular framework (test script modularity ).
2. test library architecture ).
3. keyword-driven testing Framework (keyword-driven/table-driven testing ).
4. data-driven testing framework ).