Should tests be in the same Ruby file or in separated Ruby files?
- by Junior Mayhé
While using Selenium and Ruby to do some functional tests, I am worried with the performance. So is it better to add all test methods in the same Ruby file, or I should put each one in separated code files?
Below a sample with all tests in the same file:
# encoding: utf-8
require "selenium-webdriver"
require "test/unit"
class Tests < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :firefox
@base_url = "http://mysite"
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
@wait = Selenium::WebDriver::Wait.new :timeout => 10
end
def teardown
@driver.quit
assert_equal [], @verification_errors
end
def element_present?(how, what)
@driver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def verify(&blk)
yield
rescue Test::Unit::AssertionFailedError => ex
@verification_errors << ex
end
def test_1
@driver.get(@base_url + "/")
# a huge test here
end
def test_2
@driver.get(@base_url + "/")
# a huge test here
end
def test_3
@driver.get(@base_url + "/")
# a huge test here
end
def test_4
@driver.get(@base_url + "/")
# a huge test here
end
def test_5
@driver.get(@base_url + "/")
# a huge test here
end
end