[Spring] webtestclient와 rest docs 사용시 NullPointerException
💡
파링은 스프링을 사실상 거의 처음 써보는것임을 알아주세요. 내용이 정확하지 않을 수 있습니다.
그냥 제가 잘 못찾은거같긴 한데 일단 써볼게요
문제는 context가 null이라는 거였어요. 그 이유를 찾아보니 잘 모르겠더라고요? 그래서 코드를 뜯어봤어요. 그렇게 결론은? beforeTest를 실행해주지 않아서였어요.
@WebFluxTest
@AutoConfigureRestDocs
class ApiControllerTests(
@Autowired
val client: WebTestClient,
@Autowired
val restDocumentation: ManualRestDocumentation
): StringSpec({
afterEach {
restDocumentation.afterTest()
}
beforeEach {
restDocumentation.beforeTest(javaClass, "ApiControllerTests")
}
"hello world" {
client.get().uri("/").exchange().expectStatus().isOk
.expectBody().consumeWith(document("Hello"))
}
})
뭐 이러니까 해결이 되긴 하더라고요...? 만약 더 좋은방법이 있다면 알려주면 감사할거같아요!