0

I've following code:

require 'test/unit'

class Flow < Test::Unit::TestCase
    def test_hi
        puts "Hi"
    end

    def test_working
        puts "Working"
    end

    def test_bye
        puts "Bye"
    end

    def test_tired
        puts "Tired"
    end
end

When I run it, it displays following:

Bye
Hi
Tired
Working

Looking at output, I can guess that the tests are executed in alphabetical order of the test names(i.e. alphabetical order of text field in test_text).

Actually, I want to execute my test in the order which I defined. Means for above script, I want following output:

Hi
Working
Bye
Tired

How can I achieve that?

Castrohenge
  • 8,525
  • 5
  • 39
  • 66
Alpha
  • 13,320
  • 27
  • 96
  • 163

1 Answers1

4

Although I agree with Sergio that this should not be done, I found this by looking at the source of Test::Unit::TestCase

(https://github.com/test-unit/test-unit/blob/master/lib/test/unit/testcase.rb):

    # Sets the current test order.
    #
    # Here are the available _order_:
    # [:alphabetic]
    #   Default. Tests are sorted in alphabetic order.
    # [:random]
    #   Tests are sorted in random order.
    # [:defined]
    #   Tests are sorted in defined order.
    def test_order=(order)
      @@test_orders[self] = order
    end

So, if you set the test_order of the TestCase to :defined, it should be working.

mario
  • 1,248
  • 9
  • 9
  • I tried with test_order = :defined but it's not working as expected and when I tried self.test_order = :defined it throws error: test.rb:4:in `': undefined method `test_order=' for Flow:Class (NoMethodError) from test.rb:3:in `
    '
    – Alpha Jun 25 '13 at 15:59
  • Thanks mario for pointing to doc. It's helping to understand Test:Unit – Alpha Jun 26 '13 at 05:28
  • No problem, this was just the natural choice to look for references. Although I am still puzzled why this does not work as advertised. – mario Jun 26 '13 at 08:32