我已经关注了代码:
require 'test/unit'
class Flow < Test::Unit::TestCase
def test_hi
puts "Hi"
end
def test_working
puts "Working"
end
def test_bye
puts "Bye"
end
def test_tired
puts "Tired"
end
end
当我运行它时,它会显示以下内容:
Bye
Hi
Tired
Working
查看输出,我猜测测试是按测试名称的字母顺序执行的(即test_text中文本字段的字母顺序)。
实际上,我想按照我定义的顺序执行测试。以上脚本的手段,我想要以下输出:
Hi
Working
Bye
Tired
我怎样才能做到这一点?
答案 0 :(得分:4)
虽然我同意Sergio认为不应该这样做,但我通过查看Test :: Unit :: TestCase
的来源找到了这个。(https://github.com/test-unit/test-unit/blob/master/lib/test/unit/testcase.rb):
# Sets the current test order.
#
# Here are the available _order_:
# [:alphabetic]
# Default. Tests are sorted in alphabetic order.
# [:random]
# Tests are sorted in random order.
# [:defined]
# Tests are sorted in defined order.
def test_order=(order)
@@test_orders[self] = order
end
因此,如果您将TestCase的test_order设置为:defined,它应该正常工作。