My Spring Boot Tests Passed, but Production Failed: The H2 vs. PostgreSQL Trap
Tags: #java #springboot #testing #postgresql #programming
Your Spring Boot application passes every test. Your CI pipeline is green. You deploy with confidence.
Then production fails because a database query that worked in your tests does not work with PostgreSQL.
How can this happen?
One possible reason is that your tests use H2, an in-memory database, while production uses PostgreSQL.
Although both databases support SQL, they do not behave identically. Their SQL syntax, data types, constraints, locking behavior, and other database-specific features can differ.
In this article, we will build a small example, understand the problem, and replace misleading database tests with integration tests against a real PostgreSQL instance using Testcontainers.
1.…