Ruby-用rake随机执行测试 [英] Ruby - Executing tests in a random order with rake
本文介绍了Ruby-用rake随机执行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让我的Rails应用测试以随机顺序执行? 有使用rake的简单解决方案吗?
How can I have the tests for my Rails app to be executed in a random order? Is there a simple solution using rake?
推荐答案
在这里,请在lib/tasks/tasks.rb
namespace :test do
namespace :randomize do
desc "Randomize tests"
Rake::TestTask.new(:all => "db:test:prepare") do |t|
t.libs << "test"
t.test_files = Rake::FileList[
'test/unit/**/*_test.rb',
'test/functional/**/*_test.rb',
'test/integration/**/*_test.rb'
].shuffle
t.verbose = true
end
end
end
运行:rake test:randomize:all
请记住,文件内测试仍将按照它们出现的顺序执行.我猜您可以通过猴子补丁测试单元来实现这一点.
Keep in mind that within file tests will still be executed in the order they appear. I guess you could monkey patch test unit to allow for that.
这篇关于Ruby-用rake随机执行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文