knut
knut

Reputation: 27875

Why does Test::Unit.test_order= not working as expected?

There is the question In Ruby, how to I control the order in which Test::Unit tests are run? and wanted to answer with a reference to test_order = :defined,

The documentation for Test::Unit::TestCase.test_order says:

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.

So I thought this would execute the tests in order of method definition:

gem 'test-unit'
require 'test/unit'
class Mytest < Test::Unit::TestCase
  test_order = :defined
  #~ test_order = :random
  #~ test_order = :alphabetic #default
  def test_b
    p :b
  end
  def test_a
    p :a
  end
  def test_c
    p :c
  end
end

But when I execute it (tested with test-unit 2.4.9 and 2.5), I get the alphabetic order:

Started
:a
.:b
.:c
.

What's the problem? Is there something missing in my code, is the documentation wrong or is there a bug?

Upvotes: 4

Views: 872

Answers (1)

knut
knut

Reputation: 27875

I detected the solution, or better my fault:

gem 'test-unit'
require 'test/unit'
class Mytest < Test::Unit::TestCase
  self.test_order = :defined
  #~ self.test_order = :random
  #~ self.test_order = :alphabetic #default
  def test_b
    p :b
  end
  def test_a
    p :a
  end
  def test_c
    p :c
  end
end

The difference: I used test_order = :defined in my class. What happened: A local variable test_order was created.

With self.test_order = :defined the method test_order= is called.

Upvotes: 3

Related Questions