Reputation: 1468
I am currently developing cleanup/migration code for our database. I want to run this code once when one or more of our database tests is ran (we have some non-database tests as well, and it is not needed run the cleanup/migration code).
I have already looked at the @BeforeClass
annotation, but it runs for every class. So when I run 10 database tests, the cleanup/migration code will run 10 times as well, which is not really good for performance.
I was not able to find a good solution yet, so does anyone know a good solution?
Thanks.
Upvotes: 1
Views: 46
Reputation: 5070
Check out DBUnit - it provides exactly what you're looking for - database build & teardown, plus all sorts of cleanup.
http://dbunit.sourceforge.net/
Upvotes: 1