8. Scenario
• Given
• 初期条件を定義する
• When
• 実行するアクションを定義する
• Then
• whenで記載した処理を実行したときに期待する結果を定義する
Feature: テストフィーチャー
Scenario: 未ログインで存在しないページを表示
Given I am not logged in
When I go to "foobar"
Then I should get a 404 HTTP response
21. Given I am logged in as a "role"
「Given I am logged in as a "role"」ではランダムなユーザが作成され
る。作成されたユーザはテスト終了後に削除される。
/**
* Creates and authenticates a user with the given
role(s).
*
* @Given I am logged in as a user with the :role role(s)
* @Given I am logged in as a/an :role
*/
public function assertAuthenticatedByRole($role)
{
// Check if a user with this role is already logged in.
if (!$this->loggedInWithRole($role)) {
// Create user (and project)
$user = (object) [
'name' => $this->getRandom()->name(8),
'pass' => $this->getRandom()->name(16),
'role' => $role,
];
$user->mail = "{$user->name}@example.com";
//中略
}
22. デバッグ方法
「Then (I )break」でテストを一時的に中断してデバッグするができる。
例えば以下のように「 I break」を記載した場合はユーザが作成された状
態で中断する。
@api
Scenario: writer can create node
Given I am logged in as a "writer"
And I break
When I go to "/node/add/basic"
Then I should not see "Published" in the "select" element
And I should see "Draft" in the "select" element