목표
- 응답 값에 특정 필드의 값이 null이 아니라, 완전히 존재하지 않는지 검증이 필요했다.
해결
- 아래와 같이 json 경로를 쓰고,
doesNotHaveJsonPath()
메서드로 테스트할 수 있다.
.andExpect(jsonPath("$.keyToNull").doesNotHaveJsonPath()))
doesNotExist
는 해당 경로의 값이 null인 경우에도 통과되어 버린다.
doesNotHaveJsonPath()
메서드로 테스트할 수 있다..andExpect(jsonPath("$.keyToNull").doesNotHaveJsonPath()))
doesNotExist
는 해당 경로의 값이 null인 경우에도 통과되어 버린다.