MENU

Fun & Interesting

Transactional Gotchas in Spring Boot Tests

Tales from the jar side 3,903 2 years ago
Video Not Working? Fix It Now

Did you know that when you run transactional tests in Spring Boot applications, a rollback in the tests doesn’t cause a rollback in the database? I certainly didn’t. This video demonstrates the problem (and how at first I got “lucky” with JUnit default ordering of my tests), and how to fix it. Testing transactions can be tricky, but it is manageable once you know how. Tales from the jar side, newsletter: https://kenkousen.substack.com Tales from the jar side, videos: https://www.youtube.com/@talesfromthejarside GitHub repository: https://github.com/kousen/shopping_v3 00:00 - Welcome 04:14 - Testing the Repository 08:00 - Testing the Controller in a Running Server 10:36 - A Naive Controller Test 12:39 - JUnit test order 15:33 - Transactions in tests != Transactions on server 23:40 - Conclusions

Comment