This bundle provides a class for a simple API Test. The tests run on the terminal using run.php
.
In the folder you will find run.php
. Run this file with given params to setup the test engine.
If you have written some tests. Then you can execute them with:
$ php run.php -u <api url> -t <test dir> -m <mock dir> -n <number of rounds> -c <concurrency level>
Example:
php run.php -u "http://httpbin.org" -t "jsons/" -m "mocks/" -n 10 -c 2
First of all, all tests must contain in the same folder, sub folder are ignored.
###Create a simple test###
A test can contain one or more subtests.
{
"tests" : [
{
"name" : "Try to login with a wrong data",
"path" : "/login",
"method" : "POST",
"request_params" : {
"email" : "[email protected]",
"password" : "12345678"
},
"validation" : {
"http_code" : 406,
"response_params" : {
"code" : 406,
"message" : "$nn"
}
}
},
...
]
}
Options
- $nn - means should be "not null"
- $eq - means check variable 1 of a response is equal to variable 2
- .$c - will return the count of the keypath (used for arrays)
- $ia - means check variable is an array
- more options in the next version ...
###Save variables###
To reuse output or created data you can save them to the globals (note: use unique keys!). Keypath should be a available path inside the request response.
"save_global" : [
{ "key" : "account_id", "keypath" : "account.id" }
]
To reuse the save variable you can do it easy with {$account_id}
"name" : "Delete account with id {$account_id}",
"path" : "/accounts/{$account_id}",
###Using mocks###
If you have create mocks, you can easy load them by adding a string to the request_params
. This example will load the mock account.json
.
"request_params" : "account",
You can also use mocks to validate the response values. For this add mock
inside the validation.
"validation" : {
"http_code" : 200,
"mock" : "account"
},
###Extended Header###
You can extend and overwrite the reuqest header using the header
in the test set. The header variables will also listing to the global saved variables.
"header" : {
"Authorization" : "Bearer {$access_token}"
}