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
We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case.
test-unit (Test::Unit) is unit testing framework for Ruby, based on xUnit principles. These were originally designed by Kent Beck, creator of extreme programming software development methodology, for Smalltalk's SUnit. It allows writing tests, checking results and automated testing in Ruby.
Most methods can be tested by saying, “When I pass in argument X, I expect return value Y.” This one isn't so straightforward though. This is more like “When the user sees output X and then enters value V, expect subsequent output O.” Instead of accepting arguments, this method gets its value from user input.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With