Testing with Real PostgreSQL via Testcontainers and MockMvc

Testcontainers + MockMvc Most developers test their database code against an in-memory database. It's fast, it's easy to set up, and it lies to you. Your production app runs on PostgreSQL. Your tests run on H2, which has a different engine, different behavior, and different edge cases. You can have 100% passing tests and still ship a bug that only exists in production. So I made a different choice. My integration tests spin up a real PostgreSQL container via Testcontainers, run every assertion, then tear it down. My end-to-end tests go one step further using MockMvc to fire real HTTP requests through the full Spring stack, hitting the actual controller, service, repository, and database. No shortcuts at any layer. No mocks. No surprises in production. Testcontainers (testcontainers.com) makes this easy; it supports Java, Go, Python, .NET, and has native integration with Spring Boot 3+. Not the easiest path. The correct one. --- 💬 Do you test against a real database or an in-memory one? Drop it in the comments. 🔗 Full project: https://lnkd.in/dse3hHTV 🔗 Testcontainers: https://testcontainers.com #Java #SpringBoot #Testing #BackendDevelopment #SoftwareEngineering

  • diagram

To view or add a comment, sign in

Explore content categories