- Testing Bash applications by Nikita Sobolev;
- Testing Your Shell Scripts, with Bats by Tim Perry;
- xUnit Patterns:SUT(system under test);
bats-core
- Bats Evaluation Process;
-
echo $output >&3
:将被测函数的输出打印到屏幕; - 在被测函数的 echo 语句中不使用
*
,避免进行 Filename Generation(被解释成当下目录的所有文件); -
echo "$output" >&3
:必须在 bats 命令行指定 -t 参数可以起作用;
Comparison
No. | tools | language | star | release | date | description |
---|---|---|---|---|---|---|
1 | bats-core | Shell | 355 | 1.1.0 | July 2018 | Bats |
<1 | bats | Shell | 4905 | 0.4.0 | Aug 2014 | Bash Automated Testing System |
2 | bash_unit | Shell | 79 | 1.6.1 | Feb 2018 | bash unit testing enterprise edition framework for professionals ! |
3 | shunit2 | Shell | 527 | 2.1.7 | Jan 2018 | xUnit unit test framework |
4 | assert.sh | Shell | 361 | 1.1 | Feb 2015 | bash unit testing framework |
5 | roundup | Shell | 385 | 0.0.6 | Jan 2015 | eliminate bugs and weeds from shell scripts |
6 | shelltestrunner | Haskel | 36 | 1.9 | Jan 2018 | Easy, repeatable testing of CLI programs/commands |
7 | bashtest | python | 24 | 0.0.7 | Aug 2016 | UNIX command-line tool for testing bash/sh scripts |
8 | BeakerLib | Shell | 11 | 1.17 | May 2018 | shell-level integration testing library |
参考
- Unit testing for shell scripts @ stackoverflow;
- TAP(Test Anything Protocol)
- Unit Testing bash scripts @ stackoverflow;
it's possible to import (include, whatever) a procedure (function, whatever it's named) from an external file. That's the key to writing a testing script: you break up your script into independent procedures that can then be imported into both your running script and your testing script, and then you have your running script be as simple as possible.
This method is like dependency injection for scripts, and sounds reasonable.