gpt4 book ai didi

ruby-on-rails - 为什么 Test::Unit 测试用例启动如此缓慢?

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:24 25 4
gpt4 key购买 nike

>rails -v
Rails 1.2.6

>ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

当我像这样运行测试夹具(测试 Rails 模型类)时,需要 20-30 秒才能开始执行这些测试(显示“已加载套件...”)。给了什么?

>ruby test\unit\category_test.rb

require File.dirname(__FILE__) + '/../test_helper'

class CategoryTest < Test::Unit::TestCase
def setup
Category.delete_all
end
def test_create
obCategoryEntry = Category.new({:name=>'Apparel'})
assert obCategoryEntry.save, obCategoryEntry.errors.full_messages.join(', ')
assert_equal 1, Category.count

assert_not_nil Category.find(:all, :conditions=>"name='Apparel'")
end
#.. 1 more test here
end

这是一个使用 MySql 数据库的 Rails,没有固定装置。这次它的启动时间为 30 秒以上。

最佳答案

看看这个Rails Test Server .

引用作者的话:

"Every time you run a test in a Rails application, the whole environment is loaded, including libraries that don’t change between two consecutive runs. That can take a considerable amount of time. What if we could load the environment once, and only reload the changing parts before each run? Introducing RailsTestServing.

With RailsTestServing, the run time of a single test file has gone from 8 seconds down to .2 of a second on my computer. That’s a x40 speed improvement. Now, I don’t think twice before hitting ⌘R in TextMate. It feels liberating!"

(这是我在上周的 Rails Envy Podcast 上找到的。)

关于ruby-on-rails - 为什么 Test::Unit 测试用例启动如此缓慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/323363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com