# How to print the results of pm.test in console?

**URL:** <https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417>\
**Category:** Help Hub\
**Tags:** tests, result\
**Created:** [January 22, 2021, 6:14am UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417 "2021-01-22T06:14:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarekalba](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tarekalba](https://community.postman.com/u/tarekalba)\
**Post date:** [January 22, 2021, 6:14am UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/1 "2021-01-22T06:14:23Z")

</div>

I want to show the results of pass/fail that comes from pm.test in console, I want to print it using e.g. console.log.

Thanks.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 22, 2021, 11:49am UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/2 "2021-01-22T11:49:58Z")

</div>

The result of the assertions is already available in the tests tab of the response pane for a request.

If you need additional information, you can use console.log and the data will show up in the console.

---

<div class="post-metadata">

**Author:** ![tarekalba](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tarekalba](https://community.postman.com/u/tarekalba)\
**Post date:** [January 22, 2021, 12:45pm UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/3 "2021-01-22T12:45:40Z")

</div>

Hi @allenheltondev. thanks mate, but I need to know how to print the pm.test results specifically in the console.  
The purpose is I am making a sort of a test management environment where I send results of each test cases’ steps for record keeping.

The console.log doesn’t show the results of pm.test, and specifically I am trying to show the results of my schema validation.

I would love if you have a solution on how to print the results of schema validation, not necessarily using pm.test.

Thanks.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 22, 2021, 1:00pm UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/4 "2021-01-22T13:00:00Z")

</div>

I really think I’m missing something fundamental in what you’re trying to do.

I’m assuming you’re using javascript in the tests tab of the request to run the assertion. When I do schema validation in Postman I use ajv. So if I wanted to print the results of ajv to the console I would just do:

```auto
const valid = ajv.validate(mySchema, jsonData);
const errors = ajv.errorsText(valid.errors);
console.log(errors);

```

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 22, 2021, 4:34pm UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/5 "2021-01-22T16:34:53Z")

</div>

```
pm.test("Status code is 200", function () {

    try {

        pm.response.to.have.status(500);

    } catch (e) {

        console.log(e)

        throw Error(e)

    }

});

```

just wrap except with try catch , and throw the exception back as an error

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 22, 2021, 4:43pm UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/6 "2021-01-22T16:43:34Z")

</div>

You’d only see the fails in the console that way though right? If the assertion passed, it wouldn’t log anything 😃 I think you would also only see the first failed assertion and not all assertions.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/d/3d8448ffe4a5cdfe4d66d117dbe486a879d6403a.png)

The original question was about passes and fails, although the question is a little vague.

> [@tarekalba](#):
>
> I want to show the results of pass/fail that comes from pm.test in console, I want to print it using e.g. console.log.
> 
> Thanks.

@tarekalba Can you provide more context and an example of what you’re trying to achieve, please?

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [January 22, 2021, 4:58pm UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/7 "2021-01-22T16:58:02Z")

</div>

If pass then add a custom console message in the try block , if fail then print in console inside catch block.

But as @dannydainton pointed out this use case doesn’t sound as good practice @tarekalba make sure you are not reinventing the wheel .

if you just have to print message with assertiong you can do like

```auto
 pm.test("Explicitly ", function () {
    let Ajv = require('ajv');
    let ajv = Ajv()
    let result = ajv.validate(schema, jsonData);
    pm.expect(result, JSON.stringify(ajv.errors)).to.be.true;
});

```

---

<div class="post-metadata">

**Author:** ![tarekalba](https://avatars.discourse-cdn.com/v4/letter/t/4491bb/32.png) [@tarekalba](https://community.postman.com/u/tarekalba)\
**Post date:** [January 23, 2021, 1:44am UTC](https://community.postman.com/t/how-to-print-the-results-of-pm-test-in-console/19417/8 "2021-01-23T01:44:09Z")

</div>

Thanks guys, my solution as @allenheltondev is the following:

pm.test(“Validation schema”, () =\> {pm.response.to.have.jsonSchema(schema);});

var Ajv = require(‘ajv’),

```
ajv = new Ajv({logger: console});

```

const valid = ajv.validate(schema, pm.response.json());

const errors = ajv.errorsText(valid.errors);

console.log(errors);
