testing

webtest and jWebUnit: first impression

I spent a little bit of time check out both webtest and jWebUnit. Here are my first impression:

webtest is declarative and XML configuration file driven. If you like configuration management more than programming, you might like this format. All you need is edit the test definition and hit the run command, no compilation necessary. If you have well formed HTML and working JavaScript, then you should not have too much trouble running this. My initial simple test case works once I commented out the non-working and irrelevant JavaScript reference in the HTML. I tried to take another mini-step forward by attempting to “configure” a click to select one of the link items in a JavaScript widget. Webtest has 3 ways to click on a link, by ID, label, or xPath. The widget’s link item doesn’t have an ID, so I can’t use that. I tried label and that didn’t work. Then I tried xPath and that didn’t work for me either. So, that second mini-step didn’t go very far for me. Any one know an open source xPath validation tool or web site?

jWebUnit is one of the many unit testing frameworks based on jUnit/HtmlUnit. The interesting aspect of this framework is that it supports both HtmlUnit and Selenium test cases. jWebUnit uses similar programmatic model as jUnit, so you can stay comfortable within your favorite IDE. I was able to create a new project in NetBeans and leverage it’s jUnit feature, by creating an unit test and rewrite that as a jWebUnit test case, while using NetBeans to drive the test execution. jWebUnit, or the underlying HtmlUnit engine appears more picky about JavaScript than Webtest, I had to start tweaking YUI libraries in an attempt to load a page, which shouldn’t be something that I supposed to be doing anyway. Perhaps YUI engineers use a different unit testing framework. The test page actually loads without a major issue in Firefox.

Both frameworks do share one thing in common, both do not use actual browser instances to drive the testing. And that explains why they don’t work as well as some of testing frameworks that built within or on the real browser instance because of behavior differences when processing JavaScript. At the same time, both may have one advantage over browser based testing framework, which is the ability for non-interactive testing through ant and is very useful for continuous integration servers such as CruiseControl. Again, I’ve only looked a few testing frameworks and let me know if you know a browser based unit testing framework that works with ant. Thanks.

Chris Richardson on Testing

During JavaOne 2007, I attended Chris Richardson’s talk on Minimalist Testing Techniques for Enterprise Java Technology-Based Applications. Beyond the usual JUnit and CruiseControl, he mentioned a few new interesting names: JMock, EasyMock, and Selenium. Both JMock and EasyMock are object mock-up frameworks that allow a developer to focus on unit test a module independent from others. In order to use this, a team needs to agree on interfaces among modules before creating such mock-ups. Seleium is a web application testing tool that focus on browser compatibility and functional testing. It runs within a browser and has its own IDE for test development. These are certainly interesting testing tools.

My initial impression on JUnit with NetBeans 5.5 rc1

JUnit has been around for a long time. And Junit has been in NetBeans for sometime now. If I remember correctly, I did play with integrated JUnit in NetBeans a year or two ago. Now I am trying it out again and it certainly is pretty easy to use. I just click my way through creating generic tests case and execute them. NetBeans just take care of the rest and let me focus on the actual test logic. I find it a very good way for me to document my assumptions while I write code. This also allows me to test a small feature at a time and helps me to build confidence that my code actually works while I am developing it. This incremental approach certainly is a good way to write code.