# Automatically create test for current response

**URL:** <https://community.postman.com/t/automatically-create-test-for-current-response/5697>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 31, 2019, 9:32am UTC](https://community.postman.com/t/automatically-create-test-for-current-response/5697 "2019-05-31T09:32:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmitryb.dev](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@dmitryb.dev](https://community.postman.com/u/dmitryb.dev)\
**Post date:** [May 31, 2019, 9:32am UTC](https://community.postman.com/t/automatically-create-test-for-current-response/5697/1 "2019-05-31T09:32:56Z")

</div>

Usually, when I’m writing tests, I already have correctly working HTTP endpoints. It means, when I click the “Send” in postman, the response is correct or sometimes almost correct. So I want to commit the current behaviour with tests. So most often I just write assertions for current response.

So my suggestion is next.

Let say, I have some endpoint, GET [https://jsonplaceholder.typicode.com/todos/1](https://jsonplaceholder.typicode.com/todos/1). When I send it, the server produces the response:

```auto
200 Ok
Body:
{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}

```

I want to have a button, maybe in the SNIPPETS panel, maybe named “Assertion for current response”, that will generate the next test:

```auto
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

pm.test("Body is correct", function () {
    pm.response.to.be.json;
    
    const response = pm.response.json();
    pm.expect(response.userId).to.eql(1);
    pm.expect(response.id).to.eql(1);
    pm.expect(response.title).to.eql("delectus aut autem");
    pm.expect(response.completed).to.eql(false);
});

```

> <https://github.com/postmanlabs/postman-app-support/issues/6620>

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [May 31, 2019, 11:41am UTC](https://community.postman.com/t/automatically-create-test-for-current-response/5697/2 "2019-05-31T11:41:30Z")

</div>

I like this feature, it would be cool if we could add our own snippets in Postman
