Script with Postbot 이란.
Postbot이 Tests의 Script를 작성해주는 기능으로, 최근에 업데이트 되었다.
기본 Request 뿐 아니라, Collection에 Request 들의 Tests Script를 바로 작성해주는 장점이 있는듯 하다.
각 화면의 위치는 아래 참고
사용법
1. Send를 한번 요청해서, Body에 내용이 출력되게끔 한다.
(Reques를 한번 하지 않을 경우에는, "You'll need a valid response before tests can be generated.") 안내 문구가 출력된다.
Response가 있을 경우에는 Script with Postbot에 "Add tests to this request" 만 선택해도, 몇초 뒤 Script가 자동으로 추가된다.
결과
저 Add tests to this request를 선택했을 때, wiremockapi 에서 내려오는 응답값은 id와 value가 딱 2개밖에 안되지만 tests로 응답 값, type, 응답 속도, property 까지 작성을 완료한다.
pm.test("Response status code is 200", function () {
pm.expect(pm.response.code).to.equal(200);
});
pm.test("Id should be a non-negative integer", function () {
const responseData = pm.response.json();
pm.expect(responseData).to.be.an('object');
pm.expect(responseData.id).to.be.a('number');
pm.expect(responseData.id).to.be.at.least(0, "Id should be non-negative");
});
pm.test("Validate that value is a non-empty string", function () {
const responseData = pm.response.json();
pm.expect(responseData.value).to.be.a('string').and.to.have.lengthOf.at.least(1, "Value should not be empty");
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});
pm.test("Response has required fields - id and value", function () {
const responseData = pm.response.json();
pm.expect(responseData).to.be.an('object');
pm.expect(responseData).to.have.property('id');
pm.expect(responseData).to.have.property('value');
});
그리고 내가 원하는 Script를 작성할 수도 있는데, 한글로 작성해도 전달이 잘되는거 같다, 물론 좀 더 써봐야겠지만?

Postman 블로그 글
https://blog.postman.com/postbot-is-now-in-open-beta/
Postbot Is Now in Open Beta—Try it Today | Postman Blog
We are thrilled to announce that Postbot is now in open beta with big improvements, bringing generative AI right into your Postman workspace.
blog.postman.com
참고해서 잘 쓴다면 backend test를 여러모로 쉽게 사용할 수 있을거 같다.
'Postman' 카테고리의 다른 글
newman (0) | 2023.09.06 |
---|---|
environment 설정 (0) | 2023.08.15 |
Postman (0) | 2023.07.30 |