Should tests be in the same ruby file or in separeted ruby files?

Posted by Junior Mayhé on Programmers See other posts from Programmers or by Junior Mayhé
Published on 2012-11-08T17:57:03Z Indexed on 2012/11/08 23:16 UTC
Read the original article Hit count: 296

Filed under:
|
|

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

© Programmers or respective owner

Related posts about ruby

Related posts about selenium