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?
We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case.
They make sure that a section of an application, or a “unit”, is behaving as intended. In a Rails context, unit tests are what you use to test your models. Although it is possible in Rails to run all tests simultaneously, each unit test case should be tested independently to isolate issues that may arise.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With