🎪 놀고있네/Postman
[Postman] Test Script 사용하기 - 데이터 타입 확인하기
냥장판
2022. 4. 6. 17:35
반응형
예시로 테스트 해볼 수 있는 사이트들이 꽤 있는데,
https://jsonplaceholder.typicode.com/
여기서 특정 데이터가 가지는 데이터 타입을 테스트해볼 수 있는 테스트 스크립트이다.
위와 같은 body 를 가진 데이터가 있을 때, 타입을 확인하는 테스트 스크립트는 아래와 같다.
데이터 구조에 따라 다르겠지만 참고하길 바람!
// Asserting a value type
const responseJson = pm.response.json();
pm.test("Test data type of the response", () => {
pm.expect(responseJson).to.be.an("array");
pm.expect(responseJson[0].id).to.be.a("number");
pm.expect(responseJson[0].address).to.be.an("object");
pm.expect(responseJson[0].name).to.be.a("string");
});
반응형