Guice persist by itself does not support this feature

There are a few approaches you could take

1. Jukito
Jukito is a JUnit4 test runner. It adds guice support to JUnit. Thous it allows to inject Objects into methods (this includes @After method). You could take advantage of this and have your DB cleaned up in an after method.

2. JUnit4 Rule
You could write your own JUnit4 Rule. There are several tutorials on the net. Also a good start to look in some code is the TemporaryFolder rule.

3. DB Unit + H2
If you are using H2 or another light weight in memory DB for your tests you can spin up an instance for every test. To ensure a base setup in the DB you can then use DB Unit or similar tools to provision the data for your test

4. Unique Business Keys
If every entity has a business key besides the technical ID than you can use random generated business keys (or random pre-/postfixes) to make sure that two concurrently running tests are not interfering with each other. This may be the most demanding approach because you also need to make sure every test is cleaning up behind itself or otherwise data garbage will start to accumulate.


I'm sure there are at least half a docent more approaches but those 4 were on top of my mind.



On 14.05.2018 07:19, Sharath Gururaj wrote:
Sprint provides the ability to rollback transactions on success in test cases. This allows each test case to start from a clean initial state.

How can I implement the same behaviour with guice-persist?
--
You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com <mailto:google-guice+unsubscr...@googlegroups.com>. To post to this group, send email to google-guice@googlegroups.com <mailto:google-guice@googlegroups.com>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/da0a4d31-d9e0-4ca4-8d30-cfc6c6b40b68%40googlegroups.com <https://groups.google.com/d/msgid/google-guice/da0a4d31-d9e0-4ca4-8d30-cfc6c6b40b68%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/9f998ec9-f942-66a4-07af-23796cd11e25%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to