skip to content

Persistence & Integration Testing

Testing against real persistence: transactional rollback, SQL scripts, TestEntityManager, Testcontainers, service connections and dynamic properties. Interviewers ask about this because tests that pass on H2 and fail on Postgres are a familiar story.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

When would you choose @Sql over alternatives like Flyway/Liquibase migrations, spring.sql.init scripts, or programmatic seeding — and what are its transaction/isolation tradeoffs at scale?

level: principalimportance: nice to knowfreq 25%

basics

~10 s

Use @Sql for per-test data setup/teardown that varies by test. Use Flyway/Liquibase for schema and shared reference data. Prefer transactional rollback for isolation; use @Sql(ISOLATED) or AFTER cleanup only when tests commit.

open as a page

showing 31–31 of 31