Ruby - Executing tests in a random order with rake

℡╲_俬逩灬. 提交于 2019-12-10 03:24:36

问题


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!


来源:https://stackoverflow.com/questions/1376267/ruby-executing-tests-in-a-random-order-with-rake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!