What is the best practice? How should I imple开发者_如何学Pythonment it so that the database isn't polluted?
If you want to perform integration tests on code that accesses database, you may benefit from using DBUnit. DBUnit can load test data into the database before each test. This can help you compare the result of the test case against an expected set of values.
This blogpost of mine describes a process of unit-testing using spring, hibernate and maven. The maven part can be substituted with your particular build facilities.
Тesting Struts (not Structs, I guess) depends on your struts/spring integration. Anyway take a look at StrutsTestCase and this article about StrutsUT
For Hibernate unit testing you can use HSQL DB :
Unit-testing should have as few barriers as possible. For relational databases those barriers range from external dependencies (is the database running?) to speed to keeping the relational schema synchronized with your object model. For these reasons it is vital to keep database access code away from the core object model and to test as much as possible without touching a real database.
http://www.theserverside.com/tt/articles/article.tss?l=UnitTesting
精彩评论