개발이야기
incompatible types JsonPathResultMatchers cannot be converted to org.springframework.test.web.servlet.ResultMatcher
클라인STR
2021. 4. 1. 22:47
package com.kknd.brave.springboot.web;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
//import static org.assertj.core.internal.bytebuddy.matcher.ElementMatchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.hamcrest.Matchers.is;
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = HelloController.class)
public class HelloControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void helloReturn() throws Exception {
String hello = "hello";
mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string(hello));
}
public void helloDtoReturn() throws Exception {
String name = "Hello";
int amount = 10000;
mvc.perform(
get("/hello/dto")
.param("name", name)
.param("amount", String.valueOf(amount)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.amount", is(amount)))
.andExpect(jsonPath("$.name", is(name)));
}
}
import import static org.assertj.core.internal.bytebuddy.matcher.ElementMatchers.is 되어 있는걸
import static org.hamcrest.Matchers.is; 변경한다.