Question

I'm trying to implement shoulda for test automation. I tried this code:

require 'test/unit'
require 'shoulda'
require 'shoulda-context'

class TestClass < Test::Unit::TestCase
  context 'Languages' do
    should 'Ruby' do
      puts 'Ruby'
    end

    should 'Java' do
      puts 'Java'
    end

    should 'Python' do
      puts 'Python'
    end
  end
end

When I execute that code, it outputs according to alphabetical order of shoulda test methods:

Java
Python
Ruby

Actually, I want the output in the order I wrote the methods:

Ruby
Java
Python

To do that, what will I have to use in my code?

Was it helpful?

Solution

Actually it is preferred not to run test in a specific order. It is better to run them in a random order, because that allows you to recognize if there are tests that depend on other tests. If tests only pass in a specific order, it is a indicator that you are doing something wrong.

If you want to do that nevertheless:

class TestClass < Test::Unit::TestCase
  context 'Languages' do
    self.test_order = :defined
    ...

See: http://test-unit.rubyforge.org/test-unit/en/Test/Unit/TestCase.html#test_order=-class_method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top