This is a simple API Test-Engine. With simple JSON files you can run tests for all your RESTful API's.
This bundle provides a class for a simple API Test. The tests run on the terminal using run.php
., (*1)
, (*2)
In the folder you will find run.php
. Run this file with given params to setup the test engine., (*3)
If you have written some tests. Then you can execute them with:, (*4)
$ php run.php -u <api url> -t <test dir> -m <mock dir> -n <number of rounds> -c <concurrency level>
Example:, (*5)
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., (*6)
A test can contain one or more subtests., (*7)
{ "tests" : [ { "name" : "Try to login with a wrong data", "path" : "/login", "method" : "POST", "request_params" : { "email" : "empty@me.com", "password" : "12345678" }, "validation" : { "http_code" : 406, "response_params" : { "code" : 406, "message" : "$nn" } } }, ... ] }
Options, (*8)
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., (*9)
"save_global" : [ { "key" : "account_id", "keypath" : "account.id" } ]
To reuse the save variable you can do it easy with {$account_id}
, (*10)
"name" : "Delete account with id {$account_id}", "path" : "/accounts/{$account_id}",
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
., (*11)
"request_params" : "account",
You can also use mocks to validate the response values. For this add mock
inside the validation., (*12)
"validation" : { "http_code" : 200, "mock" : "account" },
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., (*13)
"header" : { "Authorization" : "Bearer {$access_token}" }