
HtmlUnit
HTML 뷰의 테스트를 전문적으로 하기 위해서 사용하는 툴 입니다.
의존성 추가하기
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | <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>
 
 | 

두 가지의 의존성을 추가합니다.
테스트 클래스
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 
 | @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("junjang");
 }
 }
 
 | 
 WebClient라는 의존성을 주입받아 HtmlUnit을 통해 테스트를 진행합니다.
 WebClient라는 의존성을 주입받아 HtmlUnit을 통해 테스트를 진행합니다.
이처럼 MockMvc보다 더 전문적으로 HTML에 대해서 테스트를 할 수 있습니다.
더 많은 사용법을 알고 싶으면 상단에 홈페이지에 자세히 나와있으니 참고하시면 됩니다.