biluochun2010
biluochun2010

Reputation: 119

How to run MiniTest::Unit tests in ordered sequence?

MiniTest runs my test cases in parallel. Is there a way to force running test cases in sequence?

def test_1
end

def test_2
end

How can I force test_1 running before test_2?

Upvotes: 6

Views: 4397

Answers (2)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84443

Make Your Tests Order-Dependent with MiniTest

If you want to force ordered tests, despite the brittleness of doing so, you can invoke Minitest::Test#i_suck_and_my_tests_are_order_dependent!. The documentation says:

Call this at the top of your tests when you absolutely positively need to have ordered tests. In doing so, you're admitting that you suck and your tests are weak.

Test cases should really be independent. Order-dependent tests are a code smell, and the opinionated name of the MiniTest method makes it quite clear that the MiniTest authors think you need to be doing something else with your code.

State should be defined in setup and teardown blocks, rather than in test ordering. YMMV.

Upvotes: 3

falsetru
falsetru

Reputation: 369424

You can use i_suck_and_my_tests_are_order_dependent!() class method.

class MyTest < MiniTest::Unit::TestCase
  i_suck_and_my_tests_are_order_dependent!   # <----

  def test_1
    p 1
  end

  def test_2
    p 2
  end
end

But as the name suggest, it's not a good idea to make the tests to be dependant on orders.

Upvotes: 26

Related Questions