Testing Terminal Apps

Sometimes you need to test a terminal application, which reads user inputs from terminal and prints results to terminal.  These tasks are very common in introductory programming courses. Simple testing tool can help here, and students can learn good practices – automatic testing – from the very beginning.  I’ve been looking around and does not find anything, simple enough, that ie can be used by beginner and provide basic actions – for  testing output of program and supplying inpu to itt.  So I created such tool – simpletest. (written in Python, using pexpect)

You just need to create test script as text file, where lines are started by > (for expected output) or  < (for supplying input into program).  Here is trivial example of the test script:

For this script:

 

And here is result of running it:

And here other scripts, which yields  error:

Usage is very simple,  key advantage is that user can just copy interaction with program from terminal to text editor, quickly amened it and test script is ready.

There are couple more features – checking return code (?),  running program ($), line continuation (\\) and sending control control characters, which together provide everything one needs to create simple test cases. More in tool readme file.

Tool can be easily installed via pip ( if you do not have pip on your system you can install with sudo apt-get install python-pip on Debian/Ubuntu,  more details about installing pip):

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">