Search code examples
postmanpostman-testcase

How to get postman tests to Fail - mine are always passing?


I'm writing a simple Postman test that even checks if true == false but it always passes. What am I doing wrong? You can see the green light here:

enter image description here

Just a single test on its own without the wrapper function will fail [good!], but that doesn't seem a scalable way to write a lot of tests.

so wrapping stuff in pm.test( ) with either a function() or an ()=> arrow function means everything false passes... ???

enter image description here

enter image description here

If I use a test runner, or check test results below I can see the fails. So maybe that little happy green light in the test authoring panel is just buggy / should be ignored? Or maybe it means syntax error rather than results error? Confusing.

enter image description here


Solution

  • I think there is a misunderstanding here. pm.expect(true).to.eql(false); throws an error. If it is wrapped by a test, this error is being caught. If no test wrapper, it's not being caught.

    The red/ green dot next to "Tests" just indicates if the Javascript has been executed without problems. So if you execute this as a test, the Javascript went trough without errors, thus the green dot. Because the error has been caught by the test function. If you only execute the .expect() without a test, the error is not caught, thus the Javascript failed, thus the red dot.

    Did you check the Test Results area at the bottom? There you can clearly see, that a test which expects true to equal false is failing.

    enter image description here