views:

284

answers:

6

If I have java-webapp (servlets), what is the best way to create automated tests for this application?

Should I start a server? But that is very fragile. Should I call the servlets directly? But how can this be done? I don't know how to create a ServletResponse/ServletRequest.

And what is the best way to test the functionality of the webapp? Should I check the generated HTML-text? But if I change the templates (typo) the test is broken.

What are your best practices and experiences with testing webapps?

+1  A: 

Same problem. On my TODO list I have jetty and httpunit.

Also, if you're using some kind of framework (Spring, Struts, etc.) you can often test the pieces separatedly without the need to deploy the whole stuff.

agnul
+6  A: 

Have a look at Selenium. It's a very nice tool, and should at least point you in the right direction for the integrated tests. Beyond that, use unit tests of your servlets and other support classes using JUnit.

Nerdfest
+2  A: 

Look at Selenium for webapp testing, and Abbott for java applet testing. We've managed to mix the two so that Selenium calls the Abbott test via javascript. They're both tools that allow you to record actions as you view the page, and then autogenerate test code. You can modify and tweak it once you've recorded the basic test. You get beautiful tests with a minimal amount of effort. They'll name a drink after you.

Kieveli
+1  A: 

I use htmlunit almost exclusively and have no complaints. Once we built up a decent set of test utility methods, it was pretty easy to test even complex web applications. It works a treat with javascript, too. We've even used it without problems with AJAX applications.

Terry Lacy
A: 

I test web applications all day, and I use Watir.

Željko Filipin
A: 

Hi Kieveli,

Can you provide some examples of how you used abbot with selenium? Even, i got stucked with selenium failing to record or understand an applet. Your example or code will really help us bind together the tests we wanted to run.

Basically, iam looking at as how you configure,call and run abbot from selenium? As well anyexample of how you recorded a script on an applet application using abbott.

Thanks! Santhosh

Santhosh
Please, post this as a new question, don't hijack an existing one. And by the way, Keiveli won't be notified by this answer so, really, you should open a new question.
Pascal Thivent