Reputation: 312
I'm using JPA to store my java objects in a database using javadb.
Now i've written JUnit tests to check whether the objects are correctly stored and removed etc. from the javadb.
The problem is that modifications to the database in previous tests impact later tests and, more importantly, obviously modify the database that i'm using for my application.
One solution i found was reversing the transaction for each test, but since several of the methods i'm testing already commit their transaction I don't think this would work for me.
I also thought about creating a backup by storing all the data in a file and restoring the database afterwards or making a created persistence.xml with a different jdbc.url value (that will somehow be used when i'm running the tests instead of the original) and creating a separate database.
But i've got no idea how to make either of those solutions work or if they are even good solutions.
So could anyone explain to me how to exactly go around avoiding modifications to the original database while running these tests?
Upvotes: 1
Views: 207
Reputation: 312
I ended up just using maven with a seperate persistence.xml that configured a different javadb database purely for running tests as explained here.
I didn't use DBUnit as Alan Hay's comment suggested, because of time constraints, but this seems a valid option as well.
Upvotes: 1