12. テストを実行する
テストの実行コマンド及び実行結果は以下のようになる。
$ cd {drupal_root}
$ vendor/bin/behat features/test.feature
Feature: テストフィーチャー
Scenario: 未ログインで存在しないページを表示 # features/test.feature:4
Given I am not logged in # DrupalDrupalExtensionContextDrupalContext::assertAnonymousUser()
When I go to "foobar" # DrupalDrupalExtensionContextMinkContext::visit()
Then I should get a 404 HTTP response # DrupalDrupalExtensionContextMinkContext::assertHttpResponse()
1 scenario (1 passed)
3 steps (3 passed)
0m0.16s (14.67Mb)
13. テストがNGの場合
テストがNGの場合は以下のように表示される。
Feature: テストフィーチャー
Scenario: 未ログインで存在しないページを表示 # features/test.feature:4
Given I am not logged in # DrupalDrupalExtensionContextDrupalContext::assertAnonymousUser()
When I go to "foobar" # DrupalDrupalExtensionContextMinkContext::visit()
Then I should get a 200 HTTP response # DrupalDrupalExtensionContextMinkContext::assertHttpResponse()
Current response status code is 404, but 200 expected. (BehatMinkExceptionExpectationException)
--- Failed scenarios:
features/test.feature:4
1 scenario (1 failed)
3 steps (2 passed, 1 failed)
0m0.25s (14.77Mb)
15. 定義されているテストケース
定義されているテストケースは以下のコマンドで確認することができる。
$ {drupal_root}/vendor/bin/behat -dl
default | Given I am an anonymous user
default | Given I am not logged in
default | Then I log out
default | Given I am logged in as a user with the :role role(s)
default | Given I am logged in as a/an :role
default | Given I am logged in as a user with the :role role(s) and I have the following fields:
default | Given I am logged in as :name
17. 参考文献
• 駆動開発が多すぎる件
• TDD(テスト駆動開発)とは?開発手法、メリットをわかりやすく解説
• TDD/BDDにおける「振る舞い」の意味するところとは何なのか
• Testing your site with the Drupal Extension to Behat and Mink
• How to use behavior-driven development in Drupal with Behat
• docomoinnovations/drupalextension
• Drupal 8 に Drupal 向け Behat のスタンドアロンでの導入とシンプルなテストシナリオの作成