How can I have the tests for my Rails app to be executed in a random order? Is there a simple solution using rake?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here you go, define this in 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
Run: 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.
回答2:
You may wish to check out "ZenTest 3.9.0: now with more Evil" (can't do a direct link, use google's cache)
Added ability to set test execution order, defaults to :random. EVIL!