Sign inSign up

benweese/postman

By benweese

•Updated almost 7 years ago

Image
0

593

benweese/postman repository overview

⁠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

CircleCI Actions Docker Cloud Build Status

GitHub GitHub issues StackShare

⁠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

⁠Credits

Ben Weese⁠

Tag summary

Content type

Image

Digest

Size

59.9 MB

Last updated

almost 7 years ago

docker pull benweese/postman