HTmlUnit is the GUI-less browser for Java programs to simulate the browser functionality. This tool is primarily used for testing the web applications for simulating the browsers. This tool is not intended for using it as stand alone project, it has to be used as part of the another testing framework like JUnit or TestNG. This tool itself used as the underlying browser for many of the UI testing frameworks like Canoo WebTest, JWebUnit, WebDriver, JSFUnit, WETATOR, Celerity, etc.
Spring IO has its own testing framework Spring Test MVC. This framework could test the controllers and injected wores. However, testing the HTML views could be challenging for the normal testing framework unless it has its own UI testing framework. Spring Test MVC announced its†Spring Test MVC HtmlUnit 1.0.0.M1.†With this, it will be easy to test the HTML views in the spring applications.
Read : Spring Test MVC Framework
Spring Test MVC and HtmlUnit eases testing of HTML based views by providing:
- Integration with HtmlUnit
- Integration with WebDriver via HtmlUnitWebDriver For an example see MockMvcCreateMessageTest
- Geb Spock integration For an example see CreateMessagesISpec
- Easily mocking services for fast & thorough testing on views and controllers. For example, you can quickly and easily test behavior when no results should be produced, one page of results, two pages of results, etc.
Maven Configuration for Spring Test MVC and HtmlUnit Integration
<repository> <id>spring-milestone</id> <url>https://repo.spring.io/milestone</url> </repository> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test-mvc-htmlunit</artifactId> <version>1.0.0.M1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test-mvc-htmlunit</artifactId> <version>1.0.0.BUILD-SNAPSHOT</version> <scope>test</scope> </dependency>
You can refer more details in the official website.