Demo: fixing leaking test data
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
find and fix tests that depend on each other. Prepares JNR-045-LAB1.
Draft outline details
Step by step
- Show two tests that pass alone but one fails when run together.
- Find the cause: both insert the same email, or one counts all rows.
- Run in random order (JUnit method order setting) to reproduce.
- Fix with unique data per test and a cleanup in
@BeforeEach. - Planned mistake: adding
@Transactionalto a test that uses real HTTP and seeing the leak remain; explain why and use cleanup instead. - Run the suite ten times to confirm.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.