为什么 Test::Unit 测试用例启动这么慢? [英] Why do Test::Unit testcases start up so slowly?

查看:46
本文介绍了为什么 Test::Unit 测试用例启动这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>rails -v
Rails 1.2.6

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

当我像这样运行测试装置(测试 Rails 模型类)时,开始执行这些测试需要 20-30 秒(显示加载的套件...").什么给?

When I run a test fixture (that tests a rails model class) like this, it takes 20-30 secs to start executing these tests (show the "Loaded suite..."). What gives?

>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 DB 的 Rails.这次它的启动时间为 30 秒以上.

This one is Rails using a MySql DB with no fixtures. This time it clocked 30secs+ to startup.

推荐答案

看看这个 Rails 测试服务器.

引用作者的话:

"每次在 Rails 中运行测试时应用程序,整个环境是已加载,包括未加载的库两次连续运行之间的变化.这可能需要相当多的时间.如果我们可以加载环境一次,并且只重新加载每次运行前更换零件?介绍 RailsTestServing.

"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.

使用 RailsTestServing,运行时间单个测试文件已经从 8秒到我的 0.2 秒电脑.这是 x40 的速度改进.现在,我不再犹豫在 TextMate 中点击 ⌘R 之前.它感觉很自由!"

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 上的特色内容,我就是在那里发现的.)

(This was featured on the Rails Envy Podcast this past week which is where I found this.)

这篇关于为什么 Test::Unit 测试用例启动这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆