pm.test('Status code is 0', () => {
pm.expect(pm.response.statusCode).to.equal(0);
});
您可以使用pm.response.to.be.ok作為簡寫來測試狀態(tài)代碼是否為 0。
測試響應時間
對于具有一元方法的請求,您可以斷言響應時間:
pm.test('Response time is below 200ms', () => {
pm.response.to.have.responseTime.below(200);
// or
pm.response.to.have.responseTime.not.above(200);
// Using pm.expect
pm.expect(pm.response.responseTime).to.be.below(300);
});
pm.test('"content-type" is present in response metadata', () => {
pm.response.to.have.metadata('content-type');
// Using pm.expect
pm.expect(pm.response.metadata.has('content-type')).to.be.true;
});
您還可以斷言元數(shù)據(jù)的值:
pm.test('"content-type" response metadata is "application/grpc"', () => {
pm.response.to.have.metadata('content-type', 'application/grpc');
// Using pm.expect
pm.expect(pm.response.metadata.get('content-type')).to.equal('application/grpc');
});
pm.test('"grpc-status-details-bin" is present in response trailers', () => {
pm.response.to.have.trailer('grpc-status-details-bin');
// Using pm.expect
pm.expect(pm.response.trailers.has('grpc-status-details-bin')).to.be.true;
});
您還可以斷言預告片的價值:
pm.test('"grpc-status-details-bin" response trailer is "dummy-value"', () => {
pm.response.to.have.trailer('grpc-status-details-bin', 'dummy-value');
// Using pm.expect
pm.expect(pm.response.trailers.get('grpc-status-details-bin')).to.equal('dummy-value');
});
更多建議: