We have a large collection of command-line utilities that we write ourselves and use frequently. At the moment, testing them is very cumbersome and consequently, we don't do as much testing as we aught to.
I am wondering if anyone can suggest good techniques or tools for doing a good job of this kind of thing.
This is UNIX.
The CLI tests are integration tests - they test the CLI as a standalone application. Originally an attempt was made to write tests with java and junit. But jline hangs when testing the CLI in the same JVM as Junit.
Windows users - Touchpad settings Or, press Windows key + I to open Settings, then click Devices, Touchpad. In the Touchpad window, make sure the Touchpad On/Off toggle switch is set to On. If it's Off, change it to be in the On position. Test the touchpad to see if it works.
If you run the command brew doctor, you can verify that the installation was successful: $ brew doctor Your system is ready to brew. You'll use the python3 command when you configure your text editor, when you start a Python terminal session, and when you run programs from the terminal.
The command to run the tests is python -m unittest filename.py . In our case, the command to run the tests is python -m unittest test_utils.py .
I recommend structuring your command line tool's code so that the command line utility is a client to a library of functions and/or classes.
Rather than simply using std::cout to print output, have the libraries function take an ostream reference that defaults to std::cout. When you are testing, provide a std::stringstream to collect the output.
Finally, simply compare your utility's output with expected results using your favorite unit testing framework.
(I apologize for the C++ specific example... I'm sure there are ways to do similar things in other languages too).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With