2016-09-05 3 views
0

:テストで間違っMinitestはなぜ私にとって遅いですか? Minitestは、3つのテストを実行するために52秒を取っていないあなたは私が遅れを診断して修正することができます

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ディレクトリがないことに注意してください。

+2

3つのアサーションのみ...あなたのテストを教えてください。 – fbelanger

答えて

0

これは、ActionController::TestCaseのようには見えません。ActionDispatch::IntegrationTestです。

test/controllers/static_pages_controller_test.rbである必要があります。通常はより複雑なやりとりのために予約されており、より多くの機能が含まれているので、IntegrationTestを使用することができます。

An integration test spans multiple controllers and actions, tying them all together to ensure they work together as expected. It tests more completely than either unit or functional tests do, exercising the entire stack, from the dispatcher to the database.

代わりにこのコードを試してみてください。

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

EDIT

私は、単一の非常に簡単なテストの比較を実行し、かなり短い思い付きました。私はそれがこのような劇的な違いを引き起こすようには思わない。

# 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に変更がありますか?もしそうなら、私たちを見せてもらえますか?

+0

誰も読むことができないイメージではなく、プレーンテキストをプレーンテキストとして投稿してください。 – tadman

+0

'ActionController :: TestCase'に変更すると、' ActionController :: UrlGenerationError: 'エラーが発生します。 これはマシンパフォーマンスの問題であるかどうか、このパフォーマンスの問題をどのように絞り込むかの指針になりますか? – jbk

+1

あなたの見ているエラーがあなたのURLパスと関係しています。 'get static_pages_about_url'を実行する代わりに、' get:about'のようなものを試してみてください。この問題を解決して、パフォーマンスの問題を絞り込んでください。そうでなければ、他にもたくさんのものがあります:https://blog.codeship.com/faster-rails-tests/ – fbelanger

関連する問題