gradle 기본셋팅 후
webcontroller 생성
@RestController
public class WebController {
@GetMapping
public String test() {
return "hello";
}
}
test code 작성
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
class WebControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
void findsTaskById() throws Exception {
mockMvc.perform(get("/"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string("hello"));
}
}
기본 path "/" 호출시 status가 ok이면서 content가 hello 인지 확인
'Programming > Springboot' 카테고리의 다른 글
[springboot/jpa] jpa crud example 2 (0) | 2020.10.26 |
---|---|
[springboot/jpa] jpa crud example 1 (0) | 2020.10.26 |
[springboot] @autowired 안에서 @value로 호출한 값 못 읽을때 (0) | 2019.03.13 |
[springboot] jar 실행시 profile 선택 (0) | 2019.01.09 |
[springboot] springboot + spring security + jpa + thymeleaf (1) | 2017.06.15 |