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.
I think that the method *test_order* should be a class method and not a instance method like so:
i_suck_and_my_tests_are_order_dependent!
may be a later addition to minitest & not available as a Ruby core method. In that case, you'd want to force use of your gem version:The best way to interfere in this chain may be to override a class method runnable_methods:
You can reorder test any suitable way around. If you define your special ordered tests with
, don't forget to remove them from the results of super call.
In my example I need to be sure only in one particular test to run last, so I keep random order on whole suite and place 'run_last' at the end of it.
Note that, as of
minitest
5.10.1, thei_suck_and_my_tests_are_order_dependent!
method/directive is completely nonfunctional in test suites usingMiniTest::Spec
syntax. TheMinitest.test_order
method is apparently not being called at all.EDIT: This has been a known issue since Minitest 5.3.4: see seattlerb/minitest#514 for the blow-by-blow wailing and preening.
You and I aren't the ones who "suck". What's needed is a BDD specification tool for Ruby without the bloat of RSpec and without the frat-boy attitude and contempt for wider community practices of MiniTest. Does anyone have any pointers?
If you just add test_order: alpha to your test class, the tests will run in order: