0
0
Postmantesting~5 mins

Response time assertions in Postman

Choose your learning style9 modes available
Introduction

Response time assertions check if a web service or API responds quickly enough. This helps ensure users get fast results and a good experience.

When testing an API to make sure it responds within an acceptable time.
When monitoring a website to detect slowdowns or performance issues.
When comparing response times before and after code changes.
When setting performance goals for a new feature.
When verifying that a third-party service meets its promised speed.
Syntax
Postman
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

pm.test defines a test with a name and a function.

pm.response.responseTime gives the response time in milliseconds.

Examples
This test checks if the response time is under 500 milliseconds.
Postman
pm.test("Response time is less than 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});
This test uses a different assertion style to check the response time is at most 1000 milliseconds.
Postman
pm.test("Response time is not more than 1000ms", () => {
    pm.expect(pm.response.responseTime).to.be.at.most(1000);
});
This test ensures the response time is more than 100 milliseconds, useful for detecting too-fast responses that might indicate caching issues.
Postman
pm.test("Response time is greater than 100ms", () => {
    pm.expect(pm.response.responseTime).to.be.above(100);
});
Sample Program

This test checks if the API response time is under 300 milliseconds. If the response is slower, the test will fail.

Postman
pm.test("Response time is less than 300ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(300);
});
OutputSuccess
Important Notes

Response time is measured in milliseconds (ms).

Set realistic thresholds based on your API and user expectations.

Too strict limits may cause false failures during network delays.

Summary

Response time assertions help check API speed.

Use pm.response.responseTime to get response time in Postman tests.

Choose thresholds that match your performance goals.