백기선(인프런 강의)/스프링 부트 개념과 활용
HtmlUnit
레알윙
2020. 5. 10. 19:23
반응형
HTmlUnit 이란?
http://htmlunit.sourceforge.net/
http://htmlunit.sourceforge.net/gettingStarted.html
html을 단일 테스트하기 위한 tool이다.
webClient를 만들어서 사용하며, webClient로 특정한 페이지로 요청하여 결과를 받아서 테스트할 수 있다.
thmeleaf랑 같은 예제
사용법
pom.xml에 의존성 추가
<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>
@RunWith(SpringRunner.class)
@WebMvcTest(SampleController.class)
public class SampleControllerTest {
@Autowired
WebClient webClient;
@Test
public void hello() throws Exception {
HtmlPage page = webClient.getPage("/hello");
HtmlHeading1 h1 = page.getFirstByXPath("//h1");
assertThat(h1.getTextContent()).isEqualToIgnoringCase("jinSeok");
}
}
반응형