Search code examples
javapostgresqlintegration-testing

How to start a postgresql instance for integration testing


Usually I use hsqldb for some integration tests and it works fine. But some test need to have a postgresql instance. As our production server run postgresql it is a good idea anyway to run the test against a production database.

Is there a maven plugin or something similar which can easily install and start a postgresql database on a given port and shut it down after all test are run?

Something like mysql-je for mysql?


Solution

  • Testcontainers is the answer. Easy to configure and just does its job. For Postgresql they have a module:

    https://www.testcontainers.org/modules/databases/postgres/

    And this way you have your test system as close as possible to the production system, which I think is a pretty good idea.