Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
share|improve this question
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 Mayhé Nov 8 '12 at 18:09
add comment

1 Answer

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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