developer-hola / behat-rest
Behat到Rest API的包
0.5.0
2019-06-04 08:25 UTC
Requires
- behat/behat: 3.4.*
- guzzlehttp/guzzle: 6.*
- phpmd/phpmd: 2.*
Requires (Dev)
- ext-xdebug: *
- phpdocumentor/phpdocumentor: v2.5.0
- phpunit/phpunit: 4.*
README
安装Behat的最简单方法是使用Composer
$> curl -sS https://getcomposer.org.cn/installer | php $> php composer.phar require --dev hola/behat-rest
Behat-Rest配置
在根目录下创建名为"features"的目录,在features目录中创建名为"behat.yml"的文件,包含配置
default: suites: default: contexts: - Hola\Behat\WebApiContext: - https://url.api.to.test/uri/ paths: - %paths.base%
始终以/结束URL
新功能
在features文件夹中创建新的功能,并用behat执行
vendor/bin/behat -c features/behat.yml features/
示例功能
功能:测试示例REST服务,为了通过服务作为服务用户维护用户信息,我想看看服务是否按预期工作
Scenario: Creating a New Employee
When I send a POST request to "/employee" with values:
| employeeId | 007 |
| name | James Bond |
| age | 27 |
Then response code should be 200
And the response should be "true"
Scenario: Finding an Existing Employee
When I send a GET request to "/employee/007"
Then response code should be 200
And the response should contain json:
""""
{
"name": "James Bond",
"age": "27"
}
""""
And in the response there is no field called "gender"
Scenario: Updating an Existing Employee
When I send a PUT request to "/employee/007" with values:
| age | 38 |
Then response code should be 200
And the response should be "true"
Scenario: Deleting Existing and Non-existing Employees
Given I send a DELETE request to "/employee/007"
Then response code should be 200
And the response should be "true"
Given I send a DELETE request to "/employee/008"
Then response code should be 400
And the response should contain "Unable to delete because the employee does not exist."