Reputation: 23
In MiniTest I know that we can make test methods run in alphabetical order, but its not feasible with the test classes . Is there any way in which we can make MiniTest run in alphabetical order of Test classes?
I know there shouldn't be any dependency between test classes as it is not a good approach, but is there at all any possible way by which we can achieve this?
Upvotes: 2
Views: 297
Reputation: 890
We figured out the solution just in case anyone is looking for one
Take a look at the following thread:
https://github.com/seattlerb/minitest/issues/514
Here is a gist from the thread just in case the link is broken:
Correct. As you can see in your gist, the test methods are still running in alphabetical order, but the test classes are not.
Test order dependencies are bugs in your tests that can and will lead to errors in production code. You should seriously consider fixing your tests so that each one is order independent. Full randomization with 100% success should be your goal. If you have a lot of tests, this can be a daunting task, but https://github.com/seattlerb/minitest-bisect can absolutely help with that.
If you're for some reason absolutely 100% dead-set on keeping your test order dependency (errors), you'll have to monkey patch Minitest.__run.
Add a initializer patching Minitest similar to the following
module Minitest
def self.__run reporter, options
suites = Runnable.runnables
parallel, other = suites.partition { |s| s.test_order == :parallel }
random, sorted = other.partition { |s| s.test_order == :random }
sorted.map { |suite| suite.run reporter, options } +
random.shuffle.map { |suite| suite.run reporter, options } +
parallel.shuffle.map { |suite| suite.run reporter, options }
end
end
Upvotes: 1