0

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
  • 1
    What aspect of performance are you worried about, and why? – Mike Partridge Nov 8 '12 at 17:59
  • the speed when running one test just after another. To put all test methods in the same file would be better for processing? – Junior M Nov 8 '12 at 18:09
3

The number of files comprising your tests will be mostly irrelevant - The time spent running the tests themselves will be much greater than the time spent loading and compiling the files.

Instead try to keep your test code manageable - group related tests together, and try to keep the files withion the very rough ballpark of 50-500 lines.

  • This. Code parsing and test method invokation will only take up an unnoticeable fraction of the time it takes to run the tests... – severin Nov 15 '12 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.