RuhrpottDev
RuhrpottDev

Reputation: 564

How can I have a clean databse for every JUnit test?

Problem: When an integration test fails, it often not delete his test data (I mostly use DbUnit for that). Because of this, other tests will also fail (for example because they want to delete their test data, but it is referenced by data which shouldn't exist at this point --> test will fail).

Is there a possibility that Jenkins use for every single test or for every Java test class a fresh/clean database with the init data (I don't need a complete empty database), that my integration tests are more independent?

Upvotes: 0

Views: 148

Answers (1)

k-wasilewski
k-wasilewski

Reputation: 4623

Use a spring.jpa.hibernate.ddl-auto=create-drop property or annotate your test class with @Transactional.

Upvotes: 1

Related Questions