Home > database >  Test in Postman to check that the From-To number is returned
Test in Postman to check that the From-To number is returned

Time:08-25

There is a query that returns the length of the key:

GET https://apitest.backendless.com/A1DA5DF0-8D22-BAC4-FF56-9A0074DC9B00/8834B7F8-88BD-4472-9051-71BE31A3EE5B/hive/rootKeys/set//UniversalKey9/length

My test checks that the length of the string is 5.

let response = pm.response.json();

pm.test("Length key (int)", () => {
    pm.expect(response, "Error").to.eql(5)
})

But the length can change, then the test will fail, how to write a test so that it checks the length of the string from 1 to 99, while "0" should not be included

CodePudding user response:

You can just use chai.js above and below chained together. Assuming response already holds the length, the test will work like this:

let response = pm.response.json();

pm.test("Length key (int) between 1 and 99", () => {
    pm.expect(response).to.be.above(0).below(100)
})

I've created a sample Postman Request that you can open and copy, that on each request generates a randomInt and tests it out. You can enter image description here

  • Related