Command line parameters testing..

A

App Ra

Hello,
I'm using Runit to write unit test for a class that takes command line
parameters.

How do I pass commandline parameters from Runit class to my actual class
that it's testing?

I'm a new bee to ruby and any help will be appreciated.

Thanks,
App
 
J

Jan Svitok

Hello,
I'm using Runit to write unit test for a class that takes command line
parameters.

How do I pass commandline parameters from Runit class to my actual class
that it's testing?

I'm a new bee to ruby and any help will be appreciated.

Thanks,
App

Passing arguments to your class instead of runit: (actually I don't
know much about Runit, but this is common style, and test/unit does it
as well, so): The trick is to deparate parameters to your class with
-- i.e. when I'm using test/unit I might do:

tc_whatever.rb -n /test_name/ -- -a -b --c --defgh ijkl

Then -n /test_name/ will be processed by test/unit and -a -b --c
--defgh ijkl will be passed to the test.


Now to testing parameters: It's better to put the command line
processing stuff into a method that you'll call with ARGV rather than
using ARGV inside the method.
That way you'll be able to test the parameter parsing without actually
messing with ARGV:

class Main
def parse_params(argv)
...
end
def run
@params = parse_params(ARGV)
end
end

class TestMain < Test::Unit::TestCase
def setup
@main = Main.new
end
def test_parse_params
assert_something xxx, @main.parse_params(%w[-c -a -b -addsa -das
--d-dsada])
assert_something yyyy, @main.parse_params(%w[-c -a -b --d-dsada])
assert_something_other @main.parse_params(%w[-c -addsa -das --d-dsada])
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top