[Tutor] unit testing

alan.gauld@bt.com alan.gauld@bt.com
Mon, 17 Sep 2001 09:33:46 +0100


If using a command line/teletype interface then they can easily 
automate teting by relying on stdin redirection. Thus write a 
little test harness that reads parameters from stdin(raw_input)
and then executes the program. This can be used ineractively 
initially but then regression testing can be done by using 
redirection from a simple text file:


C:> python myprog.py		tests interactively
C:> python myprog.py < testfile.txt >results.txt

You can then compare the results file with previous test runs.

Its an easy concept to learn and powerful enough for production use.
An interesting excercise is to compare results when they use somweone 
else's testfile... Of course they need to agree input order and formats.

> calculator. They spent a lot of time entering the same years 
> over and over again while testing their program logic.

The above option solves that bit. 

The other thing to do is *encourage* finding bugs maybe 
even rewarding in some way evidence of thorough testing.

And of course get them to test each others code.

Alan G