Improve test failure reporting in the Postman app - Show line of code that caused fail

TL; DR - Can we add stacktrace to errors or the line of code that failed?

After writing tests using Mocha/Chai in Node and then coming back to Postman was a huge bummer, primarily debugging was considerably difficult.

Give I’ll get the below response:

{
   "customer": {
       "customer_id": 21972,
       "customer_number": "TST999",
       "customer_type": "Standard",
       "company_name": "",
       "forename": "Testy",
       "lastname": "McTester",
       "email_address": "[email protected]",
       "telephone1": "1234",
       "telephone2": "1234",
       "fax": "1234"
   }
}

If I have the below code in Postman in the Tests tab:

const body = JSON.parse(responseBody);

pm.test("Expects a 200 response code", function() {
    pm.expect(responseCode.code).to.equal(200);
});

pm.test("Checks stuff", function() {
    pm.expect(body).to.have.property("customer");
    const customer = body.customer;
    pm.expect(customer).to.have.property("fax");
    // The below assertion is expected to fail
    pm.expect(customer.company_name).to.not.be.empty;
});

Postman will output the error

When running the same test in mocha/chai, I’m told which line of code failed:

Is Postman able to tell me which line of code in my ‘Tests’ tab caused the fail?
You could probably argue I should split up my tests up into proper ‘its’ but the issue raised is still valid…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.