Postman
This project is for testing APIs for practice. You can check out the Wiki for more information and learning.
Motivation
To work on my API testing skills.
Build status
Tools Used
News API
SWAPI
Continuous Intergration
Postman CLI
Json Lint
Downloads
Features
With API testing our Circle-CI runner will use Newman to run postman collections in Command line.
Code Example
Postman Json API test
//Here we create a function that is then stored in the environmental variable. This is so we can then call this from any following test.
//This must be in the first test of the collection or collection folder.
postman.setEnvironmentVariable("commonTests", () => {
//These are test that are ran on every call of the commonTest.
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Response must be valid and have a body", function() {
pm.response.to.be.json; // this assertion checks if a body exists
});
//We then create a function within commonTest for the Successful test we will run.
var positive = () => {
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response does not error", function() {
pm.response.to.not.be.error;
pm.response.to.not.have.jsonBody("error");
});
}
//This is a function for the negative test, or the test we want to fail.
var negative = () => {
pm.test("Status code is 400", function () {
pm.response.to.have.status(400);
});
}
//Lastly we return the functions, so we can call them from outside the environmental variable
return {
testType: {
positive,
negative
}
};
});
//for positive test
eval(environment.commonTests)().testType.positive();
//for negative test
eval(environment.commonTests)().testType.negative();
Documentation
- All Things Postman
- Postman Quick Reference Guide
- Postman Testing
- API testing tips from a Postman professional
- GraphQL support in Postman available for early access on canary channel
- Chai Assertion Library
- Regex Cheat Sheet
- Postman API Network
Credits
On this page
Languages
JavaScript89.8%Dockerfile10.2%
Contributors
MIT License
Created May 17, 2019
Updated February 6, 2021