Skip to content
Ameen Abozaid
Planned lessonJNR-045-L05

Test data isolation

  • Lesson 5 of 7
  • Junior
On This Lesson 4 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

keep tests independent of each other.

Planned topics

  • Shared mutable data makes tests pass or fail depending on order.
  • Options: roll back each test's transaction (@Transactional), clean tables in @BeforeEach, or use unique data per test.
  • @Transactional on tests does not roll back when the code runs in another thread or via real HTTP.
  • Prefer unique values (random email) so tests cannot collide.
  • Never rely on rows left behind by other tests.
Draft outline details

Demonstration

a @BeforeEach that truncates tables, and a helper uniqueEmail() returning user-<uuid>@test.com.

Check your understanding

Does @Transactional rollback work for a test using real HTTP calls?

Show answer

No; the server runs in another thread and commits separately.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.