Languages
[Edit]
EN

Spring Boot - rollback transaction after each @Test method (JUnit 5)

14 points
Created by:
maxsior322
347

In this short article, we would like to show how to test Spring Boot 2 Application with JUnit 5 making rollback after each @Test method is called.

That approach is useful when we want to use the same application instance across many tests.

Quick solution: 

Add @Transactional annotation for the class that contains your tests.

Example UserRestControllerTest.java file:

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join