HTMLUnit
스프링 부트에서 자동설정 지원 중이므로 의존성만 추가하자.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<scope>test</scope>
</dependency>
HTMLUnit 은 HTML 을 단위테스트하기위한 툴이다.
WebClient 를 이용해 HtmlPage 를 받아서 사용한다.
@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
@AutoConfigureMockMvc
class SampleControllerTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private WebClient webClient;
@Test
public void hello() throws Exception {
HtmlPage htmlPage = webClient.getPage("/hello");
HtmlHeading1 h1 = htmlPage.getFirstByXPath("//h1");
assertThat(h1.getTextContent()).isEqualTo("Soomin");
}
}
'SpringBoot' 카테고리의 다른 글
Spring HATEOAS (0) | 2020.11.07 |
---|---|
ExceptionHandling (0) | 2020.11.06 |
Thymeleaf (0) | 2020.11.06 |
Spring-Boot-Devtools (0) | 2020.11.05 |
HTTPS, HTTP, Connector 추가 설정 (0) | 2020.10.31 |