728x90
HtmlUnit : html을 단위테스트하기 위한 tool
> 웹 클라이언트로 요청을 보내고 결과를 받아서 내용을 HtmlPage를 통해 값을 확인할 수 있음
> 브라우저 타입을 줄 수 있음
> 엘리먼트 값을 가지고와서 값을 확인할 수 있음
예제)
Controller, template : 전과 동일
https://developing-countries.tistory.com/64
TestCode
@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
public class SampleControllerTest {
@Autowired
WebClient webClient;
@Test
public void hello() throws IOException {
HtmlPage page = webClient.getPage("/hello");
HtmlHeading1 heading1 = page.getFirstByXPath("//h1");
assertThat(heading1.getTextContent()).isEqualToIgnoringCase("sangguk");
}
}
728x90
'Spring Boot' 카테고리의 다른 글
ExceptionHandler (0) | 2022.02.28 |
---|---|
문법 (0) | 2022.02.28 |
Thymeleaf (0) | 2022.02.28 |
Spring 정적 리소스 맵핑 (0) | 2022.02.27 |
ViewResolver (0) | 2022.02.27 |
댓글