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 pageshowhide
explore
- Transactional Tests & Rollback6 questions
- @Sql Script Execution5 questions
- TestEntityManager5 questions
- @Testcontainers & @Container5 questions
- @ServiceConnection5 questions
- @DynamicPropertySource5 questions
questions
page 2 of 2When 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 sUse @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.
showing 31–31 of 31