为什么Minitest对我这么慢?

时间:2016-09-05 18:55:30

标签: ruby-on-rails testing minitest

Minitest花了52秒进行3次测试,你能帮我诊断并纠正延迟:

time bin/rake test
Running via Spring preloader in process 6302
Run options: --seed 53674

# Running:

...

Finished in 0.981134s, 3.0577 runs/s, 3.0577 assertions/s.

3 runs, 3 assertions, 0 failures, 0 errors, 0 skips


real    0m52.954s
user    0m0.431s
sys 0m0.148s

测试没有错,我猜它是测试配置问题?测试代码:

这里的实际测试:

require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test "should get home" do
    get static_pages_home_url
    assert_response :success
    assert_select "title", "Home | Ruby on Rails Tutorial"
  end

  test "should get help" do
    get static_pages_help_url
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial"
  end

  test "should get about" do
    get static_pages_about_url
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial"
  end

end

我跑了spring stop,但这并没有以任何方式加速。

我注意到我的应用没有spring目录。

1 个答案:

答案 0 :(得分:0)

这似乎更像是ActionController::TestCase而不是ActionDispatch::IntegrationTest

这应该是test/controllers/static_pages_controller_test.rb。可能是IntegrationTest的使用,因为这通常用于更复杂的交互,并包含更多功能。

  

集成测试跨越多个控制器和操作,将它们捆绑在一起以确保它们按预期一起工作。它比单元或功能测试更完整地测试,从调度程序到数据库执行整个堆栈。

请尝试使用此代码:

class StaticPagesControllerTest < ActionController::TestCase
  # ...
end

修改

我进行了一次非常简单的测试比较,结果很短。在我看来,它不会导致如此巨大的差异。

# Running tests:

.

Finished test in 0.605962s, 1.6503 tests/s, 4.9508 assertions/s.

1 tests, 3 assertions, 0 failures, 0 errors, 0 skips

对战

# Runnnig tests:

.

Finished tests in 0.297522s, 3.3611 tests/s, 10.0833 assertions/s.
1 tests, 3 assertions, 0 failures, 0 errors, 0 skips

使用ActionDispatch::IntegrationTest时仍然接近3倍。

在你的情况下也很奇怪,因为这些是静态页面。

test_helper.rb是否有任何变化?如果是的话,你能告诉我们吗?

相关问题