JUnit is a great tool for unit testing Java applications but it is little difficult to apply it and test the flow from a web application perspective. Particularly say you have unit tests for your DAO you will have to use the JDBC driver connection class to connect to the database and cannot test through JNDI as it requires a server environment. Try JUnitEE. From the site,
JUnitEE provides a TestRunner which outputs HTML and a servlet which can be used as an entry point to your test cases. Building your test harness as a standard J2EE web application means:
- Your tests are packaged conveniently into a .war file which can easily be moved between servers; you can leave the .war file in the main .ear file and simply avoid enabling the test web application on the production server.
- Your test classes will be dynamically reloaded by the app server (assuming your server supports this).
- Your test cases look just like your production code, and can use the same beans (or whatever) you use as a facade for your EJBs.