Pm.test is not failing my test even though I return false in the function

Hello there,

Today is my first day with postman. So far happy except about the below thing
Could any one please share your knowledge why the test is not failing here. Please see the attached pic to know what I am doing herewhy%20the%20test%20is%20not%20failing%20here

Thanks&Warm Regards
Musaffir

@musaffir

So this test doesn’t actually test anything here, thats why its passing. If you want it to fail, you could try changing the call or its parameters to return something other than a 200.
You can even do some sort of check that you know would fail like looking for a string.

pm.test("Does this fail?", function () {
    pm.expect(pm.response.text()).to.include("Postman FTW!");
});

Thanks you @tmccann
It makes sense to me , I thought the below point about the pm.test() function as stated here in this blog http://blog.getpostman.com/2017/10/25/writing-tests-in-postman/

  • The function accepts 2 parameters, the name of the test (as a string) and a function to return a Boolean value.

So having a function as a second parameter which returns a boolean is not going to work all the time if it is not doing the real test ? I think I will read more about this

Warm Regards
Musaffir

Hi @musaffir

The pm.test is a test block. The block is executing a bunch of assertion. This semantics is similar to a most of javascript testing frameworks. For example the it block in mocha.js.

The pm.expect extends on chai.js assertions. If you want a test that fails always you can use fail assertion method.

1 Like

Thanks @kamalaknn
It makes sense to me now , thanks again for the reply

Warm Regards
Musaffir