What are good practices for unit testing Java EE / Web applications

What are the best ways to test servlet-oriented web applications. Perhaps with jdbc support.

Front-end = Struts2 and some servlets Back-end = hibernate, some basic jdbc

+4
source share
2 answers

use mocks, easymock is one of the best frameworks (or you can use jmock if you like the name better). spring-mock has good support for mocking servlet classes.

you can also do integration testing with dbunit (to test your sqls and hqls), but it is slow and takes much longer to write and maintain. I think you should not do this unless you have a problem with people not writing bad queries or a database schema badly.

+1
source

Most importantly: design to test .

This means that you need to have small independent components (which is almost always good, and not just for verification) and test the components separately. Inversion of control (with or without an IoC map, such as Spring) can help you in this area. When you have small components, it is fairly easy to test them using jUnit, easymock, or any other standard test utilities.

Testing the interface is the most tedious and boring task. Selenium can help you, but there are no silver bullets that I know of.

0
source

All Articles