- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2017-12-15T16:03:54+09:00","default:wikiwriter","wikiwriter")
#author("2020-09-10T02:43:17+00:00","default:src128","src128")
[[FrontPage]]
&tag(MiniTest);
*目次 [#mc9d8682]
#contents
*関連ページ [#f853508a]
*参考情報 [#l4add9f8]
-[[seattlerb/minitest: minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.:https://github.com/seattlerb/minitest]]
*基本 [#k9c72096]
-RubyのTestフレームワークの一つ。
-BundlerやRailsではMiniTestが使われている。
**命名規則 [#qfb3db1b]
-先頭か末尾に"Test"を追加する。調べた感じ末尾派が多い?
-テストの名前はBookTest
-テストファイル名はbook_test.rb
**テストの実行 [#m7277b65]
-全てのテストを実行する場合
bundle exec rake test
**テストの種類 [#o96bd64b]
-[[Rails テスティングガイド | Rails ガイド:https://railsguides.jp/testing.html]]によるとテストの種類は以下の通り。
,テストの名前,英語名,テストフォルダ,役割
,単体テスト,unit test,test/models,メソッドごとのテスト
,機能テスト,functional test,test/functional,1つのコントローラーに含まれる複数のアクションをテスト
,結合テスト,integration test,test/integration,複数のコントローラー同士のやりとりをテスト
*コントローラーのテスト [#cde12c06]
-[[Rails テスティングガイド | Rails ガイド:http://railsguides.jp/testing.html]]
-以下の項目をテストする
--Webリクエストが成功したか
--正しいページにリダイレクトされたか
--ユーザー認証が成功したか
--レスポンスのテンプレートに正しいオブジェクトが保存されたか
--ビューに表示されたメッセージは適切か
-scaffoldのサンプル。
#pre{{
class ArticlesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:articles)
end
end
}}
*Tips [#pafd52e7]
**Gemプロジェクトに後からMiniTestを追加する [#db08f5c4]
-Gemプロジェクトを作成しそれを参考にするのが早い
bundle gem sampleapp -b --test=minitest
-.gemspecファイル、Rakefile、test_helper等を移植すれば動くようになる。
**特定のテストを実行 [#zbc9800d]
-ファイル単位
bundle exec rake test TEST=test/sample_test.rb
-メソッド単位
bundle exec rake test TEST=test/sample_test.rb TESTOPTS="--name=test_sample_2"
*トラブルシューティング [#y16aabfc]
**「WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated」 [#e7c2907b]
-2020/09/10(木)テストを実行すると表示されることに気がついた。
-[[Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated が出る件 – ためすう:https://blog.tamesuu.com/2019/06/08/274/]]によると、Gemfileで以下をコメントアウトする。
gem 'chromedriver-helper'