Arti said:
I tried to initalize my methods and I get an error
def initialize(name,browser,username)
@s_name=name
@browser=browser
@username=username
end #def initialize(dc)
attr_accessor :name,:browser,:username
C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/testcase.rb:59:in
`initialize': wrong number of arguments (1 for 3) (ArgumentError)
Open that file in a text editor, go to line 59, and you'll see
catch
invalid_test) do
suite << new(test) #### ERROR RAISED HERE
end
Then scroll up and you'll see you're inside the 'suite' class method of
class Test::Unit::TestCase, and higher up you'll see
def initialize(test_method_name)
...
That is, when a Test::Unit::TestCase instance is created, it takes a
single argument which is the test method name.
Almost certainly you should not be meddling with the 'initialize' method
of Test::Unit::TestCase. What exactly are you trying to do? I guess you
want to be able to run the same test suite multiple times with different
parameters? The simplest way may be
def setup
@s_name=ENV['TEST_S_NAME']
@browser=ENV['TEST_BROWSER']
@username=ENV['TEST_USERNAME']
end
Then you can do
rake test TEST_S_NAME=xxx TEST_BROWSER=yyy TEST_USERNAME=zzz
An alternative way is to have a separate class for each of your
scenarios, and share the test methods using subclassing or module
mixins. Then running the suite will run all of the variations in one go.
require 'test/unit'
class TestFoo < Test::Unit::TestCase
def setup
@browser = "foo browser"
end
def test_it
puts "Browser is #{@browser}"
assert true
end
end
class TestBar < TestFoo
def setup
@browser = "bar browser"
end
end