views:

336

answers:

4

I have a large collection of command line utilities that are 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.

Edit: to clarify this is UNIX

Thanks in advance. Tom

+3  A: 

You should be able to call them from a shell script (batch file, on MS operating systems), redirect the output to a file, then scan the file programmatically to ensure that it has the correct output. I'm not aware of a testing framework that automates this for you, but it should be fairly straight forward to set it up yourself.

Bill the Lizard
Yes - I'd hoped that someone might be aware of a framework or tool. I was thinking about knocking one up myself as your right, it wouldn't be too difficult.Cheers. Tom
Tom Duckering
A: 

You can do this from a batch file oder windows scripting host.

But i promise to use a task scheduler like (http://www.splinterware.com/products/wincron.htm) or other free/professional software.

There you can easy copy/paste the commandline-parameters which you should vary on, when you wanna test your software for about many 100 times?!

joki
A: 

I did a little bit of this (a loooong time ago hehe) using Expect to check that what happened was what I, umm, expected

LenW
A: 

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).

ceretullis