Menu

My Spring Boot Tests Passed, but Production Failed: The H2 vs. PostgreSQL Trap
📰

My Spring Boot Tests Passed, but Production Failed: The H2 vs. PostgreSQL Trap

DEV Community: java·Roveena Dsouza·1 day ago
#qLPPHQxE
#devtojava#devto#dev#java#springboot
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.