11. 1. Featureを書く
# language: en
Feature: Do Some Sample Testing
Scenario: ls
Given I am in the "directory"
When I execute "command"
Then I should get "file1,file2"
12. 2. Stepを実装する
<?php
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
/**
* @Given I am in the :arg1
*/
public function iAmInThe($arg1)
{
throw new PendingException();
}
}
13. 3. テストを実行する
./bin/behat
Feature: Do Some Sample Testing
Scenario: ls
Given I am in the "directory"
TODO: write pending definition
When I execute "command"
Then I should get "file1,file2"
1 scenario (1 pending)
3 steps (1 pending, 2 skipped)
0m0.06s (9.26Mb)
17. 2. Featureを書く
# language : en
Feature: stock search
Scenario: get stock code
Given I am on the homepage
When I follow "ファイナンス"
When I fill in "searchText" with "九州電力"
When I press "searchButton"
Then I should see "9508"
18. 3. テストを実行する
.$ ./bin/behat
Feature: stock search
Scenario: get stock code
Given I am on the homepage)
When I follow "ファイナンス"
When I fill in "searchText" with "九州電力"
When I press "searchButton"
Then I should see "9508"
1 scenario (1 passed)
5 steps (5 passed)
0m0.77s (13.74Mb)
26. 3. RestAPIテスト用拡張Step一覧
$ ./bin/behat -dl
default | When /^I set header "([^"]*)" with "([^"]*)"$/
default | When /^I set parameter "([^"]*)" with "([^"]*)"$/
default | When /^I set array parameter "([^"]*)" with "([^"]*)"$/
default | When /^I send GET request to "([^"]*)"$/
default | Then /^I should get json response equal to '([^']*)'$/
default | Then /^the response status code should be (d+)$/
default | Then /^the response content-type should be "([^"]*)"$/
default | When /^I send POST request to "([^"]*)"$/
27. 4. Featureを書く
# language : en
#
Feature: REST API TEST
Scenario: Test GET Request
When I set header "Authorization" with "Bearer 12345678"
When I set parameter "username" with "hanhan1978"
When I send GET request to "get"
Then I should get json response equal to
'{"user":"hanhan","prof":"PHPer"}'
Then the response status code should be 200
Then the response content-type should be "application/json"
28. 5. テスト実行する
Feature: REST API TEST
Scenario: Test GET Request
When I set header "Authorization" with "Bearer 12345678"
When I set parameter "username" with "hanhan1978"
When I send GET request to "get"
Then I should get json response equal to
'{"username":"hanhan1978","profile":"PHPer"}'
Then the response status code should be 200
TThen the response content-type should be application/json"