@RestController
public class WebRestController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
위의 코드를 실행하면 아래와 같은 화면이 뜬다.
아래 코드는 위의 코드에 대한 테스트 코드이다.
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = WebRestController.class)
public class WebRestControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void hello가_리턴된다() throws Exception {
String hello = "hello";
mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string(hello));
}
}
@RunWith(SpringRunner.class)
@WebMvcTest
@Autowired
@private MockMvc mvc
mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andExpect(content().string(hello))
출처: 스프링 부트와 AWS로 혼자 구현하는 웹 서비스
많은 도움된거같습니다 감사합니다 !!!