如何按照 Test 类 的字母顺序进行 MiniTests 运行 测试?
How to make MiniTests run tests in alphabetical order of Test classes?
在 MiniTest 中,我知道我们可以按字母顺序制作测试方法 运行,但它不适用于测试 类。有什么方法可以让 MiniTest 运行 以 Test 类 的字母顺序排列?
我知道测试 类 之间不应该有任何依赖关系,因为这不是一个好方法,但是有没有任何可能的方法可以实现这个目标?
我们找到了解决方案,以防万一有人在寻找
看看下面的话题:
https://github.com/seattlerb/minitest/issues/514
以下是线程中的要点,以防 link 损坏:
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.
添加类似于以下内容的初始化程序补丁 Minitest
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
在 MiniTest 中,我知道我们可以按字母顺序制作测试方法 运行,但它不适用于测试 类。有什么方法可以让 MiniTest 运行 以 Test 类 的字母顺序排列?
我知道测试 类 之间不应该有任何依赖关系,因为这不是一个好方法,但是有没有任何可能的方法可以实现这个目标?
我们找到了解决方案,以防万一有人在寻找
看看下面的话题:
https://github.com/seattlerb/minitest/issues/514
以下是线程中的要点,以防 link 损坏:
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.
添加类似于以下内容的初始化程序补丁 Minitest
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