Frisby.js is a framework used for testing the REST APIs. It is built on node.js. Furthermore it is a open-source, free tool with a good support for different platforms.
Install Frisby
1) First download and install node.jscurl --silent --location https://deb.nodesource.com/setup_5.x | sudo bash -
sudo apt-get install nodejs
2) Then install frisby.js using npm(node package manager)
npm install --save-dev frisby
3) Install jasmine too, since it is being used by frisby.js
npm install -g jasmine-node
Write Tests
- The first line is the location where frisby module is located on your local machine.
- Frisby tests start with frisby.create with a description of the test
- Then comes one of get, post, put, delete, or head
- In the middle comes many built-in test helpers like expectStatus to easily test HTTP status codes, expectJSON to test expected JSON keys/values, and expectJSONTypes to test JSON value types, among many others
- Ends with toss to generate the resulting jasmine spec test.
Sample code is shown below
IMPORTANT
File naming convention is important
- Files must end with spec.js to run with jasmine-node.
- Suggested file naming is to append the filename with _spec,
like mytests_spec.js
andmoretests_spec.js
write all the frisby tests in /spec/api folder structure
Run Tests
- Go to the parent directory of spec/api folder.
- Enter the following command
- If you have multiple spec file and if you want to run all, then you can run using following command
No comments:
Post a Comment