Current Articles | RSS Feed
If you are a web application developer and have never heard of HtmlUnit , it is time to give it a look.It is a simple API that allows you to write a Java program that can simulate a user traveling through a website. It doesn’t just read the URL into an input stream; it can parse the HTML and allows you to simulate clicking on buttons, clicking on links, firing JavaScript functions, and more.
HtmlUnit was intended to be used for UI testing. For example, let’s say you host an eCommerce Java EE application. In order to perform some testing, you would want to simulate the entire life cycle of a user creating an account, verifying the account, logging in, filling up their shopping cart, and paying for the items.Normal Java testing methods use JUnit and only test the the back-end Java code that runs on the server. This is fine and dandy, but that is not how the user uses the website. You need to use a UI test in order to truly test. While testing the back-end is extremely valuable and should never be forgotten, you are potentially not testing several key things that can only be tested using the actual browser.For example, here are some issues that cannot be tested on the back end:
While HtmlUnit is very cool and extremely powerful, it isn’t perfect. As you can imagine, web browsers are extremely complex and have invested 1000’s of hours of development to create them. The open source developers who made HtmlUnit do not have those sorts of resources and therefore are not going to be able to perfectly simulate each web browser.So apart from the HTML results of web page actions being quirky and a bit different than you’d expect at times, the other common issue is that the JavaScript engine fails to parse the JavaScript on one or more of the pages and throws exceptions. Once the JavaScript fails to parse, you will have to disable JavaScript completely.So if you find yourself performing mundane website data entry and you get sick of it, or if you need to test the full user experience through your website instead of just the backend Java code… give HtmlUnit a whirl.
Subscribe to The Enterprise Open Source Blog via emailFollow @openlogicFollow @CloudSwingThis work is licensed under a Creative Commons Attribution 3.0 Unported License.
Allowed tags: <a> link, <b> bold, <i> italics
If you read a post on The Enterprise OSS Blog, please leave a comment. Let us know what you think, even if it's just a few words. Comments do not require approval, but they are moderated.OpenLogic reserves the right to remove any comments it deems inappropriate.