Verify that a request inherits authentication from its collection
Preconditions (2)
✅ Expected Result: The request uses the authentication settings inherited from the collection and successfully authenticates, returning the expected response.
Jump into concepts and practice - no test required
pm.test('Authorization header is present', () => { const authHeader = pm.request.headers.get('Authorization'); pm.expect(authHeader).to.not.be.undefined; pm.expect(authHeader).to.not.be.empty; }); pm.test('Response status is 200', () => { pm.response.to.have.status(200); }); pm.test('Response body contains authenticated content', () => { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('user'); pm.expect(jsonData.user).to.have.property('id'); });
This test script runs after the request is sent.
First, it checks if the Authorization header is present in the request headers, confirming the request inherited the auth from the collection.
Second, it asserts the response status code is 200, meaning the request was successful and authenticated.
Third, it verifies the response body contains a user object with an id property, which is expected only if authentication succeeded.
These checks together confirm that the request correctly inherited authentication from the collection.
Now add data-driven testing with 3 different requests in the collection, each inheriting auth and verifying their own expected response content.