views:

446

answers:

3

What is the best practice? How should I implement it so that the database isn't polluted?

+1  A: 

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

SjB
+1  A: 

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.

Rahul
+1  A: 

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

Bozho
Thanks for the link, but I find your blog too general.
TiansHUo
it is quite concrete, I think. These are the exact steps I take when testing a spring app.
Bozho