Giter Site home page Giter Site logo

asifurrouf / postman-bdd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jamesmessinger/postman-bdd

0.0 2.0 0.0 6.37 MB

A BDD test framework for Postman and Newman

Home Page: http://www.getpostman.com

License: MIT License

JavaScript 28.86% HTML 71.13% TypeScript 0.01%

postman-bdd's Introduction

Postman BDD

✨ Postman now has it's own BDD test syntax ✨

Postman-BDD is no longer necessary, because Postman now has its own BDD and fluent syntax built-in!

I recommend that you start using Postman's new test syntax instead of Postman-BDD. However, if you want to continue using Postman-BDD, then you can find the original ReadMe here.

Docs

Example

// example using pm.response.to.have
pm.test("response is ok", () => {
    pm.response.to.have.status(200);
});

// example using pm.expect()
pm.test("environment to be production", () => {
    pm.expect(pm.environment.get("env")).to.equal("production");
});

// example using response assertions
pm.test("response should be okay to process", () => {
    pm.response.to.not.be.error;
    pm.response.to.have.jsonBody("");
    pm.response.to.not.have.jsonBody("error");
});

// example using pm.response.to.be*
pm.test("response must be valid and have a body", () => {
     // assert that the status code is 200
     pm.response.to.be.ok; // info, success, redirection, clientError,  serverError, are other variants
     // assert that the response has a valid JSON body
     pm.response.to.be.withBody;
     pm.response.to.be.json; // this assertion also checks if a body  exists, so the above check is not needed
});

Migration Guide

Postman's new BDD and fluent syntax are a bit different from Postman-BDD. Here are the changes you need to make to migrate your tests:

Remove describe blocks

describe() blocks were optional in Postman-BDD, and they don't exist at all in Postman's new syntax. So just remove them.

Replace it blocks with pm.test

Postman-BDD used it blocks to define tests, such as:

it('should return the correct customer', () => {
  // assertions here
});

Postman now has pm.test blocks, which work the same way. For example:

pm.test('returns the correct customer', () => {
  // assertions here
});

Move hooks to folder/collection scripts

Postman-BDD allowed you to define common assertions or setup/teardown logic in hooks, such as before(), after(), beforeEach() and afterEach(). This is no longer necessary because Postman now allows you to define test scripts for folders and collections.

Different assertion syntax

Postman-BDD used the Chai.js and Chai-HTTP assertion libraries, which let you write assertions using an intuitive, fluent, English-like syntax.

it('should return a 200 response', () => {
  response.should.have.status(200);
});

it('should set the Location header', () => {
  response.should.have.header('Location');
});

it('should return a JSON response', () => {
  response.should.be.json;
});

it('should return the correct customer', () => {
  response.body.should.have.property('id', 12345);
});

Postman now supports its own fluent assertion syntax, which is somewhat similar.

pm.test('returns a 200 response', () => {
  pm.response.to.have.status(200);
});

pm.test('sets the Location header', () => {
  pm.response.to.have.header("Location");
});

pm.test('returns a JSON response', () => {
  pm.response.to.be.json;
});

pm.test('returns the correct customer', () => {
  let jsonData = pm.response.json();
  pm.expect(jsonData.id).to.eql(12345);
});

postman-bdd's People

Contributors

jamesmessinger avatar lampei avatar rdoubleui avatar urosjarc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.