A very easy way to make your HttpUnit tests run much faster

I have been looking at the performance of our web integration tests lately. They are an order of magnitude slower than our EJB integration tests.
JavaScipt!
——-
It turns out 70% of the time taken by HttpUnit is setting up the JavaScript interpreter for each response. Some tests need this but not many. In your method where you create your default WebConversation just turn off the JavaScript as follows:
HttpUnitOptions.setScriptingEnabled(false);
WebConversation conversation = new WebConversation();
And then turn it on with HttpUnitOptions.setScriptingEnabled(true) for those WebConversations that need it.
On a test page on an AMD64 we went from 7 seconds to 1.5 for 200 test runs with this change only.
The next culprit: dom4J
——————-
We also create a DOM using dom4j in order to do XPath evaluation. This is also VERY expensive. Removing this gives about the same level of improvement. The new HttpUnit 1.6 makes resorting to XPath a little less necessary. We will gradually phase it out.

Published
Categorized as Java

By Greg Luck

As Terracotta’s CTO, Greg (@gregrluck) is entrusted with understanding market and technology forces and the business drivers that impact Terracotta’s product innovation and customer success. He helps shape company and technology strategy and designs many of the features in Terracotta’s products. Greg came to Terracotta on the acquisition of the popular caching project Ehcache which he founded in 2003. Prior to joining Terracotta, Greg served as Chief Architect at Australian online travel giant Wotif.com. He also served as a lead consultant for ThoughtWorks on accounts in the United States and Australia, was CIO at Virgin Blue, Tempo Services, Stamford Hotels and Resorts and Australian Resorts and spent seven years as a Chartered Accountant in KPMG’s small business and insolvency divisions. He is a regular speaker at conferences and contributor of articles to the technical press.