Bird
Raised Fist0
Postmantesting~10 mins

Response time assertions in Postman - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assert the response time is less than 200 milliseconds.

Postman
pm.test('Response time is less than 200ms', function () {
    pm.expect(pm.response.responseTime).to.be.[1](200);
});
Drag options to blanks, or click blank then click option'
Abelow
Bequal
Cabove
DlessThan
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'above' instead of 'lessThan' causes the test to check for greater response times.
Using 'equal' will fail if response time is not exactly 200ms.
2fill in blank
medium

Complete the code to assert the response time is at most 500 milliseconds.

Postman
pm.test('Response time is at most 500ms', function () {
    pm.expect(pm.response.responseTime).to.be.[1](500);
});
Drag options to blanks, or click blank then click option'
Abelow
BatMost
Cabove
Dequal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'above' will check for greater values, which is incorrect here.
Using 'equal' will fail if response time is not exactly 500ms.
3fill in blank
hard

Fix the error in the assertion to correctly check response time is less than 300 milliseconds.

Postman
pm.test('Response time check', function () {
    pm.expect(pm.response.responseTime).to.be.[1](300);
});
Drag options to blanks, or click blank then click option'
Aless
BlessThan
Cbelow
DgreaterThan
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'less' causes a syntax error because it is not a valid method.
Using 'greaterThan' checks the opposite condition.
4fill in blank
hard

Fill both blanks to assert response time is between 100 and 400 milliseconds.

Postman
pm.test('Response time is between 100 and 400ms', function () {
    pm.expect(pm.response.responseTime).to.be.[1](400);
    pm.expect(pm.response.responseTime).to.be.[2](100);
});
Drag options to blanks, or click blank then click option'
Abelow
Babove
ClessThan
DgreaterThan
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'above' instead of 'greaterThan' causes confusion.
Using 'lessThan' instead of 'below' is valid but inconsistent here.
5fill in blank
hard

Fill all three blanks to assert response time is less than 250ms, greater than 50ms, and not equal to 100ms.

Postman
pm.test('Complex response time assertions', function () {
    pm.expect(pm.response.responseTime).to.be.[1](250);
    pm.expect(pm.response.responseTime).to.be.[2](50);
    pm.expect(pm.response.responseTime).to.not.be.[3](100);
});
Drag options to blanks, or click blank then click option'
Abelow
BgreaterThan
Cequal
DlessThan
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'below' instead of 'lessThan' for the first blank causes inconsistency.
For the last blank, forgetting 'not.be' causes the test to check equality instead of inequality.

Practice

(1/5)
1. What does pm.response.responseTime represent in Postman tests?
easy
A. The size of the API response in bytes
B. The number of API requests sent
C. The HTTP status code of the response
D. The time taken by the API to respond in milliseconds

Solution

  1. Step 1: Understand the property pm.response.responseTime

    This property in Postman returns the time taken by the API server to send a response, measured in milliseconds.
  2. Step 2: Differentiate from other response properties

    It does not represent response size, status code, or request count, which are different properties.
  3. Final Answer:

    The time taken by the API to respond in milliseconds -> Option D
  4. Quick Check:

    Response time = API speed [OK]
Hint: Response time means how fast API replies in ms [OK]
Common Mistakes:
  • Confusing response time with response size
  • Mixing response time with HTTP status code
  • Thinking it counts number of requests
2. Which of the following is the correct syntax to assert that response time is less than 500 milliseconds in Postman test script?
easy
A. pm.test('Response time is less than 500ms', () => { pm.expect(pm.response.time).to.be.above(500); });
B. pm.test('Response time is less than 500ms', () => { pm.expect(pm.response.responseTime).to.be.below(500); });
C. pm.test('Response time is less than 500ms', () => { pm.expect(responseTime).to.equal(500); });
D. pm.test('Response time is less than 500ms', () => { pm.expect(pm.response.responseTime).to.be.above(500); });

Solution

  1. Step 1: Identify correct property and assertion method

    The correct property for response time is pm.response.responseTime. To check if it is less than 500ms, use to.be.below(500).
  2. Step 2: Verify syntax correctness

    pm.test('Response time is less than 500ms', () => { pm.expect(pm.response.responseTime).to.be.below(500); }); uses the correct property and assertion syntax. Other options use wrong properties or wrong comparison methods.
  3. Final Answer:

    pm.test('Response time is less than 500ms', () => { pm.expect(pm.response.responseTime).to.be.below(500); }); -> Option B
  4. Quick Check:

    Use pm.response.responseTime with to.be.below() [OK]
Hint: Use pm.response.responseTime with to.be.below() for less than checks [OK]
Common Mistakes:
  • Using wrong property like pm.response.time
  • Using to.be.above() instead of to.be.below()
  • Missing pm.expect wrapper
3. Given the following Postman test code, what will be the test result if the API response time is 450 ms?
pm.test('Response time is acceptable', () => {
  pm.expect(pm.response.responseTime).to.be.below(400);
});
medium
A. Test will pass because 450 is below 400
B. Test will pass because 450 equals 400
C. Test will fail because 450 is not below 400
D. Test will error due to syntax mistake

Solution

  1. Step 1: Understand the assertion condition

    The test expects pm.response.responseTime to be below 400 milliseconds.
  2. Step 2: Compare actual response time with condition

    The actual response time is 450 ms, which is greater than 400 ms, so the condition fails.
  3. Final Answer:

    Test will fail because 450 is not below 400 -> Option C
  4. Quick Check:

    450 > 400 means test fails [OK]
Hint: Check if actual time is less than threshold to pass [OK]
Common Mistakes:
  • Assuming 450 is below 400
  • Confusing pass/fail logic
  • Ignoring comparison operator meaning
4. Identify the error in this Postman test script for response time assertion:
pm.test('Response time check', function() {
  pm.expect(pm.response.responseTime).to.be.lessThan(300);
});
medium
A. The assertion method lessThan is incorrect in Postman tests
B. The function syntax is invalid
C. The property pm.response.responseTime does not exist
D. The test name is missing

Solution

  1. Step 1: Check assertion method correctness

    Postman uses Chai assertion library where the correct method to check less than is to.be.below(), not lessThan().
  2. Step 2: Verify other parts of the script

    The function syntax is valid, the property exists, and the test name is present.
  3. Final Answer:

    The assertion method lessThan is incorrect in Postman tests -> Option A
  4. Quick Check:

    Use to.be.below() not lessThan() [OK]
Hint: Use to.be.below() for less than, not lessThan() [OK]
Common Mistakes:
  • Using lessThan() instead of to.be.below()
  • Thinking lessThan() is valid Chai syntax
  • Ignoring assertion library conventions
5. You want to write a Postman test that fails if the response time is more than 1000 ms but passes if it is exactly 1000 ms or less. Which assertion code correctly implements this logic?
hard
A. pm.test('Response time check', () => { pm.expect(pm.response.responseTime).to.be.at.most(1000); });
B. pm.test('Response time check', () => { pm.expect(pm.response.responseTime).to.be.below(1000); });
C. pm.test('Response time check', () => { pm.expect(pm.response.responseTime).to.equal(1000); });
D. pm.test('Response time check', () => { pm.expect(pm.response.responseTime).to.be.above(1000); });

Solution

  1. Step 1: Understand the requirement

    The test should pass if response time is 1000 ms or less, and fail if more than 1000 ms.
  2. Step 2: Choose correct assertion method

    to.be.at.most(1000) checks if value is less than or equal to 1000, matching the requirement. to.be.below(1000) excludes 1000, to.equal(1000) only passes exactly 1000, and to.be.above(1000) is opposite.
  3. Final Answer:

    pm.test('Response time check', () => { pm.expect(pm.response.responseTime).to.be.at.most(1000); }); -> Option A
  4. Quick Check:

    Use to.be.at.most() for <= checks [OK]
Hint: Use to.be.at.most() for less than or equal assertions [OK]
Common Mistakes:
  • Using to.be.below() excludes equal value
  • Using to.equal() only matches exact value
  • Using to.be.above() reverses logic