Reputation: 499
I am trying to setup a test suite in Ruby to automate the Testing of a WebUI (using Watir)
The individual tests are fine and all run correctly, but I am having problems with the suite.
Eg if one of my tests is (where BaseTestClass extends Test::Unit::TestCase)
class Test3_1_3_1_2 < BaseTestClass
def testHeightOfMainPanel
assert(false, 'Not implemented')
end
end
In my RunAllTests script I am trying to do the following
require 'test/unit'
Test::Unit.at_start do
#Lets create our own user for these tests
createCCUser(User, Password)
end
Test::Unit.at_exit do
#Delete our own user
deleteUser(User)
end
Dir["./**/Test*.rb"].each{|s|
puts s.to_s
load s
}
So basically what I want to do is create a new user at the start of the tests, run the tests and then delete the user. This is necessary because the system is a single sign on (kinda) and if we used the same user for everyone, there is no guarantee that the tests will execute properly (ie someone else could run the test at the same time and then the first user would be kicked out)
The errors I am getting are:
undefined method at_start'
and
private method
at_exit' called
I know I am doing something wrong, but being very new to Ruby it is hard to see where. Basically what I need is a way to perform some setup run all the tests that can be found, and then do a cleanup. Each test has its own separate setup and teardown methods
I should also add, I have tried many variations of the same above, eg
require 'test/unit'
class Temp < Test::Unit::TestCase
Test::Unit.at_exit do
#Delete our own user
deleteUser(User)
end
Test::Unit.at_start do
#Lets create our own user for these tests
createCCUser(User, Password)
end
Dir["./**/Test*.rb"].each { |s|
puts s.to_s
load s
}
end
And I still don't get it. Any help would be appreciated
Upvotes: 5
Views: 1299
Reputation: 46836
I think the problem is, assuming you are using Ruby 1.9.3, is the confusion regarding which gem is being required by require 'test/unit'
.
In Ruby 1.9.3, require 'test/unit'
will require the "Minitest" gem. The methods you want to use do not exist in this gem.
The at_start
and at_exit
methods exist in the the test-unit gem.
Assuming you have both the Minitest gem (installed by default in Ruby 1.9) and Test-Unit gem (manually installed using gem install test-unit
), you need to specifically state you want the test-unit gem.
Before requiring test/unit, specify the usage of the test-unit gem:
gem 'test-unit'
require 'test/unit'
Upvotes: 5