Last active
August 3, 2016 11:49
-
-
Save chrisnicola/c45e73053b222ebda36bae27ed5d078e to your computer and use it in GitHub Desktop.
Examples of trying to set test order to be sorted. Note that I'm looking at the order that test files are being run as well. Perhaps that isn't controlled here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So far I have tried the following code in test_helper.rb | |
# Based on documentation here: http://api.rubyonrails.org/v4.2/classes/ActiveSupport/TestCase.html | |
class ActiveSupport::TestCase | |
def test_order | |
:sorted | |
end | |
end | |
# Realizing that it is a class method I changed this to | |
ActiveSupport::TestCase.test_order = :sorted | |
# Regardless in Rails 4 the default test order is supposed to be :sorted | |
# while in Rails 5 it changes to :random | |
# | |
# Also checking manually using RAILS_ENV=test rails c I can see that | |
# ActiveSupport::TestCase is fact returning :sorted | |
# Moving on to MiniTest directly | |
class MiniTest::Test | |
def test_order | |
:sorted | |
end | |
end | |
class MiniTest::Test | |
def self.test_order | |
:sorted | |
end | |
end | |
# Both of these seem to have no impact as well. Both the order the test files | |
# are executed and the order of tests within the files are still randomized. | |
# What I have had luck with is fixing the seed value when running locally. | |
# I have also tried adding `i_suck_and_my_tests_are_order_dependent!` to the | |
# TestCase base class for good measure, but I have no intention of checking | |
# in any code like that. | |
# Also considered that perhaps I was setting this too late and moved the | |
# code to `config/environment/test.rb`. I can confirm via pry breakpoint | |
# that MiniTest::Test.test_order == :sorted but tests continue to run in | |
# random order. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, thanks for tracking it down @chrisnicola. It would be nice to update minitest-spec-rails's readme if there's something you tripped on that could save others the same headache down the road, or that the very least, having your issue in the repo could help others. Thanks for taking the time to dig into it.