trouble shooting

Kyojun Jin·2024년 8월 20일
0

Insta Tistory Automator

목록 보기
5/8
  1. mockmvc는 webflux에서 동작하지 않는다. AutoConfigureWebTestClient 어노테이션을 달아서 WebTestClient를 사용해야 한다.
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
@AutoConfigureWireMock(port = PORT)
class InstaControllerTest {
    @Autowired
    private lateinit var webTestClient: WebTestClient
    
    @Test
    fun hello() {
    	val result = webTestClient.get().uri("/api/v1/hello").exchange().expectBody(String::class.java).returnResult
    }
    with(result) {
    	assertThat(status).isEqualTo(HttpStatus.OK)
        assertThat(responseBody).isEqualTo("Hello, world!")
    }
}
  1. suspend 함수는 webflux에서 동작한다. webflux 의존성과 coroutines-reactor 를 추가해줘야 한다.
runtimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.9.0-RC.2")
implementation("org.springframework.boot:spring-boot-starter-webflux")
  1. webtestclient는 SpringBootTest.WebEnvironment.RANDOM_PORT 여야 한다.
  1. SpringBootTest.WebEnvironment.RANDOM_PORT 일 때는 @Transactional 로 테스트 이후 롤백할 수 없다.

0개의 댓글