Play framework チュートリアル実践・写経メモ-10.テストの完了
残り2つ。当節はテストについて。
guide10:テストの完了
コントローラのテスト
- PlayはJUnitを使ってアプリケーションのコントローラ部分を直接テストする方法を提供(機能テスト)
- 機能テスト:HTTPリクエストをシミュレートするPlayのActionInvokerを直接呼び出す。
- テストの作成(play.test.FunctionalTestを拡張)
- 新しいテストを追加
- play test yabeでテスト起動、 http://localhost:9000/@tests にアクセス。そしてテスト実行
Seleniumテストの作成
コードカバレッジ計測
- installコマンドで導入
C:\eclipse3.6_playfw\workspace>play install cobertura ~ _ _ ~ _ __ | | __ _ _ _| | ~ | '_ \| |/ _' | || |_| ~ | __/|_|\____|\__ (_) ~ |_| |__/ ~ ~ play! 1.2.4, http://www.playframework.org ~ ~ Will install cobertura-2.4 ~ This module is compatible with: 1.2.3 ~ Do you want to install this version (y/n)? y ~ Installing module cobertura-2.4... ~ ~ Fetching http://www.playframework.org/modules/cobertura-2.4.zip ~ [--------------------------100%-------------------------] 46.4 KiB/s ~ Unzipping... ~ ~ Module cobertura-2.4 is installed! ~ You can now use it by adding it to the dependencies.yml file: ~ ~ require: ~ play -> cobertura 2.4 ~ C:\eclipse3.6_playfw\workspace>
- dependencies.xmlファイルに設定追記。
# Application dependencies require: - play -> crud - play -> secure - play -> cobertura 2.4
- 依存関係解決。
C:\eclipse3.6_playfw\workspace>play deps yabe ~ _ _ ~ _ __ | | __ _ _ _| | ~ | '_ \| |/ _' | || |_| ~ | __/|_|\____|\__ (_) ~ |_| |__/ ~ ~ play! 1.2.4, http://www.playframework.org ~ ~ Resolving dependencies using C:\eclipse3.6_playfw\workspace\yabe\conf\dependencies.yml, ~ ~ play->cobertura 2.4 (from playLocalModules) ~ ~ Installing resolved dependencies, ~ ~ modules/crud -> C:\play-1.2.4\modules\crud ~ modules/secure -> C:\play-1.2.4\modules\secure ~ modules/cobertura-2.4 -> C:\play-1.2.4\modules\cobertura-2.4 ~ ~ Done! ~ C:\eclipse3.6_playfw\workspace>
更にはapplication.confに以下の内容を追記。
|# Import the cobertura module in test mode %test.module.cobertura=${play.path}/modules/cobertura-2.4
テスト起動。全てのテストをパスさせた後、アプリケーションを停止。
03:02:45,131 INFO ~ Cobertura plugin: generating test coverage report Cobertura: Loaded information on 12 classes. Cobertura: Saved information on 12 classes. Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 12 classes. Report time: 125ms Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 12 classes. Report time: 328ms 03:02:47,633 INFO ~ Test coverage report has been generated: file:/C:/eclipse3.6_playfw/workspace/yabe/test-result/code-coverage/index.html ~ ...
- http://localhost:9000/@cobertura または yabe/test-result/code-coverage/index.html に実行結果が出力されている。
チュートリアルなのでざっくり進めたが、ここもどこかでみっちり勉強してマスターする必要があるな。coberturaはplayでなくても他のパート(Jenkins)とかでも行けるのかな?
よし、これであと1つ。