如何有效地强制Minitest按顺序运行测试? [英] How do I effectively force Minitest to run my tests in order?
问题描述
我知道.不鼓励这样做.由于我不愿讨论的原因,我需要按编写顺序运行测试.根据文档,如果我的测试类(我们将其称为TestClass)扩展了Minitest :: Unit :: TestCase,那么我应该能够调用公共方法i_suck_and_my_tests_are_order_dependent!
(Gee-您认为创建Minitest的那个人吗?对那个有什么看法?).此外,还可以选择调用名为test_order
的方法并指定:alpha
来覆盖:random
的默认行为.这些都不对我有用.
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.
这是一个例子:
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)
如果将i_suck
方法调用替换为顶部la的方法:
If I replace the i_suck
method call with a method at the top a la:
def test_order
:alpha
end
我的测试在运行,但是我可以从puts
的每种方法中得知,每次运行测试时,事物仍然以随机顺序运行.
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.
推荐答案
如果仅将test_order:alpha添加到测试类中,则测试将按以下顺序运行:
If you just add test_order: alpha to your test class, the tests will run in order:
class TestHomePage
def self.test_order
:alpha
end
def test_a
puts "a"
end
def test_b
puts "b"
end
end
这篇关于如何有效地强制Minitest按顺序运行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!