Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 = :timeout => 10

    def teardown
        assert_equal [], @verification_errors

    def element_present?(how, what)
        @driver.find_element(how, what)
        rescue Selenium::WebDriver::Error::NoSuchElementError

    def verify(&blk)
        rescue Test::Unit::AssertionFailedError => ex
        @verification_errors << ex

    def test_1

        @driver.get(@base_url + "/")
        # a huge test here


    def test_2

        @driver.get(@base_url + "/")
        # a huge test here


    def test_3

        @driver.get(@base_url + "/")
        # a huge test here


    def test_4

        @driver.get(@base_url + "/")
        # a huge test here


    def test_5

        @driver.get(@base_url + "/")
        # a huge test here

share|improve this question
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

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

Your Answer


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.