postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.85k stars 839 forks source link

Create unit tests from collection #9986

Open chainhead opened 3 years ago

chainhead commented 3 years ago

Is your feature request related to a problem? Please describe. No.

Describe the solution you'd like Once I have finalized my requests in a collection, I would like to see an option to generate unit tests out of the requests. For example, in NodeJs, these will probably be chai, mocha, etc. based test cases that I can launch with a npm test. These tests are either downloaded locally or posted to version control system such as GitHub etc.

Describe alternatives you've considered The Runner option is helpful; but, it is not native to the programming language used by a developer. Further, the tests should become a part of the larger CI/CD pipeline that the developer maybe using. Hence, this request.

Additional context None.

malvikach commented 2 years ago

@chainhead Love your ideas above!

To understand it better:

Please let me if you have tried out the above and if you have any feedback on the above.

chainhead commented 2 years ago

@malvikach limiting our discussion to NodeJs, the idea is to generate test cases in say, facebook/jest from the collection created in Postman. See here for an example of testing API end-points with facebook/jest. From the same link, for a given Collection, Postman should generate a test similar to the one below.

/* eslint-env jest */

const github = require('../github')

// A simple example test
describe('#getUser() using Promises', () => {
  it('should load user data', () => {
    return github.getUser('vnglst')
    .then(data => {
      expect(data).toBeDefined()
      expect(data.entity.name).toEqual('Koen van Gilst')
    })
  })
})

I haven't used newman; however, the idea is to keep the testing part "native" to a programming language a developer is familiar with.

While I don't mind a discussion, in the spirit of open source, perhaps, we should continue over GitHub.