ReST API Tester - R.A.T
Writing test cases and automating them are fairly time consuming activities. RAT aims to eliminate the pain of automating REST API test cases.
Current version of RAT ONLY supports JSON request and response vaidations.
Table of contents
- CLI Options
- Setting up
- Writing test cases
- Smart substituitions
npm i -g @appveen/rat
rat [options] [file ...]
The available options are,
-i, --init: Initialize the currect folder as a RAT test case location.
--ui: Start RAT in interactive mode on the CLI. This is the default behavior.
-u,--upgrade: Upgrades the RAT setup in the current folder.
-g, --generate [file ...]: Generates mocha scripts for all the files under the tests folder or for the files specified.
-r, --run [file ...]: Run all the tests under the generatedTests folder or the tests specified.
--stopOnError: Stop at the first failure while running tests
--har [file]: Generates RAT test case from a HAR file.
--clean: Displays the instructions to clean RAT setup from a folder.
--demo: Starts the demo server. This is primarily used for demoing RAT.
-v, --version: Displays the version of RAT
To set up a folder for running RAT tests, run the following commands from the command line.
rat is initialized for the first time, a set of sample test cases are provided under the tests folder.
Once initialised the following folders are created.
|generatedTests||Contains the generated test cases.|
|lib||JSON Files that are referenced by the test cases.|
|modules||Files that define JS methods|
|tests||Testcase JSON files which are used to generate the testcase under generatedTests.|
Writing test cases
Test cases are bundles as a test suite and each test suite is written as a JSON file.
- Each file is treated as a test suite or a collection of tests.
||String||Required. Name of the test case|
||List||Required. A list of URLs that will be used in this test suite|
||List||The list of module files from modules directory that is being used in the test cases.|
||List||A list of global variables that would be used in the test cases. Global varaibles are used to pass data between test cases.|
||Array||Tests is an array of objects. Each object in the array is test case.|
Sample test casefile,
||Number||Required. This denotes the URL in the list of
||String||Name of the test case. This would appear in the summary.|
||List||The delimiters that should be used for patten substituitions. The default delimiters are
||Number||The number of seconds to wait before continuing to the next text.|
||Object||Required. The request definition.|
||Object||The response data that would be used to validate the API response.|
Sample test case
||String||Required. One of the HTTP methods - POST, PUT, GET, DELETE, PATCH|
||String||Required. A uri under test.|
||JSON||A set of headers that should be sent along with the request.|
||JSON||A set of query strings that should be set on the URL.|
||Number||The HTTP status code that is expected from the response.|
||JSON||The JSON payload that should be sent with the request.|
||String||The name of the JSON file under
||String||One of the entries from
If the JSON payload is big, then it is a good practice to save the file under
liband reference the file in the test.
payloadFileis provided, then
An optional response object can be defined for a testcase. This response object is used to validate the response from the API. If no response object is provided, then no response validation is done.
||JSON||Response headers to be validated|
||JSON or Array||Response body will be validated against this. Arrays are order sensitive for comparison.|
||String||A file from
Smart substituitions allows you to specify dynamic payload.
The value from a global variable can be used in the test case by enclosing it with in the delimiters.
The delimiters for the above example are
This allows you to use the output data of a previously run test case in the current test case.