Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I effectively force Minitest to run my tests in order?

Tags:

ruby

minitest

I know. This is discouraged. For reasons I won't get into, I need to run my tests in the order they are written. According to the documentation, if my test class (we'll call it TestClass) extends Minitest::Unit::TestCase, then I should be able to call the public method i_suck_and_my_tests_are_order_dependent! (Gee - do you think the guy who created Minitest had an opinion on that one?). Additionally, there is also the option of calling a method called test_order and specifying :alpha to override the default behavior of :random. Neither of these are working for me.

Here's an example:

class TestClass < Minitest::Unit::TestCase

  #override random test run ordering
  i_suck_and_my_tests_are_order_dependent!

  def setup
    ...setup code
  end

  def teardown
    ...teardown code
  end

  def test_1
    test_1 code....
    assert(stuff to assert here, etc...)
    puts 'test_1'
  end

  def test_2
    test_2_code
    assert(stuff to assert here, etc...)
    puts 'test_2'
  end

end

When I run this, I get:

undefined method `i_suck_and_my_tests_are_order_dependent!' for TestClass:Class (NoMethodError)

If I replace the i_suck method call with a method at the top a la:

def test_order
  :alpha
end

My test runs, but I can tell from the puts for each method that things are still running in random order each time I run the tests.

Does anyone know what I'm doing wrong? Thanks.

like image 703
T-Lo Avatar asked Jan 06 '12 02:01

T-Lo


1 Answers

If you just add test_order: alpha to your test class, the tests will run in order:

class TestHomePage

def self.test_order
 :alpha
end

def test_a
 puts "a"
end

def test_b
 puts "b"
end

end 
like image 107
user3421170 Avatar answered Sep 23 '22 23:09

user3421170