# Adding PASSED/FAILED to a variable from Test Result

**URL:** <https://community.postman.com/t/adding-passed-failed-to-a-variable-from-test-result/77741>\
**Category:** Help Hub\
**Tags:** tests, variables, test-results\
**Created:** [March 27, 2025, 1:28pm UTC](https://community.postman.com/t/adding-passed-failed-to-a-variable-from-test-result/77741 "2025-03-27T13:28:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [March 27, 2025, 2:27pm UTC](https://community.postman.com/t/adding-passed-failed-to-a-variable-from-test-result/77741/2 "2025-03-27T14:27:36Z")

</div>

You can’t access the test results programmatically.

Please see the following topic for more information.

[https://community.postman.com/t/get-testresults-value-passed-failed-saved-in-a-variable](https://community.postman.com/t/get-testresults-value-passed-failed-saved-in-a-variable)

What you can do though is edit the test cast and create the variable and result here instead.

For example.

```auto
pm.test("Status code is 200", () => {
    // set inital status to fail
    pm.collectionVariables.set("testStatus", "FAILED")
    // your assertion
    pm.response.to.have.status(200);
    // If the assertion fails, then the current pm.test execution will end immediately.
    // No further code in this test block will execute.
    // The testStatus will remain as failed.
    // If the next line executes, it means that the assertion passed.
    pm.collectionVariables.set("testStatus", "PASSED")
});

```

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

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

If I force the assertion to fail by changing the status code to 201.

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

The status of the variable is now failed.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/1/7110ddf6b46b9f5e470af8606cb16f33c33b542b.png)

---

_[View the full topic](https://community.postman.com/t/adding-passed-failed-to-a-variable-from-test-result/77741)._
