Skip to content

Instantly share code, notes, and snippets.

@GantMan
Last active October 2, 2018 13:04
Show Gist options
  • Save GantMan/8c6e4a332fca455706798c69f47ada55 to your computer and use it in GitHub Desktop.
Save GantMan/8c6e4a332fca455706798c69f47ada55 to your computer and use it in GitHub Desktop.
Example API Tests for Star Wars API via Postman
// example testing:
// More found here: https://www.getpostman.com/docs/postman/scripts/test_examples
// TEST 1
pm.test("response is ok", () => {
pm.response.to.be.ok // enforce 200ish
// same as above pm.response.to.not.be.error
// HTTP good, but contents cannot say error
pm.response.to.not.have.jsonBody("error")
})
// TEST 2
pm.test("Body has string `wheeled`", () => {
pm.expect(pm.response.text()).to.include("wheeled")
})
// TEST 3
pm.test("Check Name", () => {
const jsonData = pm.response.json()
pm.expect(jsonData.name).to.eql('Sand Crawler')
})
// TEST 4
pm.test("Response time is less than 500ms", () => {
pm.expect(pm.response.responseTime).to.be.below(500)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment