--0015175907dcd571ba047f56f52f
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Feb 11, 2010 at 3:50 PM, Antoine Makhassak <twaynz / hotmail.com>wrote:

> Richard Conroy wrote:
> > What you are attempting to do here is an acceptance test, not a unit
> > test.
> > Test::Unit will facilitate both in this case.
> >
> > What you want to do is call your program from the shell, with all of the
> > correct
> > arguments, and assert that your program gives the correct output.
> >
> > THen do it again with random or incorrect arguments and verify that your
> > program gives the correct error response or exit code.
> >
> > You will also need to verify the programs side effects. (Any files that
> > it
> > creates,
> > deletes or touches),
>
>
>
> Yes I know, but I need to call my program with different arguments
> "automatically" i.e. I do not want to manually launch my program for
> each test. Can you tell me pls exactly what to enter in my .rb source
> file or a shell script / batch file so that it automatically makes the
> calls and outputs the results?
> Thank you
>

Well thats what I thought I said - you invoke the shell from within your
ruby tests with the appropriate arguments. You might find the following
articles useful:
http://tech.natemurray.com/2007/03/ruby-shell-commands.html
<http://tech.natemurray.com/2007/03/ruby-shell-commands.html>
http://www.gotripod.com/2007/10/07/tip-running-command-line-shell-commands-in-ruby-using-x/
<http://www.gotripod.com/2007/10/07/tip-running-command-line-shell-commands-in-ruby-using-x/>
http://groups.google.com/group/ruby-talk-google/browse_thread/thread/a91dfc54f53195be
<http://groups.google.com/group/ruby-talk-google/browse_thread/thread/a91dfc54f53195be>
http://www.elctech.com/snippets/executing-shell-commands-in-ruby

This assumes that your CLI app executes and returns immediately without any
further
CLI interaction. For instance, it doesn't prompt for further user input, or
have a curses style
interface. Both of which are also doable as automated tests, but they are
harder.

If you are considering using Test::Unit to do the automation, you don't need
to start with a shell
or batch file. Test::Unit allows you to define a battery of test methods,
and this is the normal
approach for dealing with inputs. If you have a very large amount of inputs
you might want to
consider using a small extension library for Test::Unit called 'dust' - it
is very easy to create
large volumes of tests, from arrays.

I wrote up some examples of using 'dust' a while ago here:
http://richardconroy.blogspot.com/2008/11/testing-java-code-with-ruby-and-jtestr.html
Its not directly appropriate to your problem, but it should give you a few
ideas of how you can
structure a large volume of test inputs, in a way that plays nice with
Test::Unit, and without
having to manually write a new test method for each input.

regards,
Richard.
-- 
http://richardconroy.blogspot.com

--0015175907dcd571ba047f56f52f--