Search code examples
spring-bootspring-data-jpah2postgisspring-boot-test

Postgis Spring Boot Integration Testing with index based operator <->


I'm currently writing an integration test with spring boot and a Postgis connection. In my original application a query uses the <-> operator. For my tests I used a h2 in-memory database with the h2gis extension. Unfortunately, the <-> is not recognized and throws a syntax error. Do you have any ideas how to do this with an in-memory database or is there only the chance to run a docker container with a proper postgis database running?

Thank you!


Solution

  • Even if it where possible to run a database similar enough to Postgres, I'd recommend against it.

    We now have Testcontainers and can therefore easily start any* database in docker container from our tests. This is preferable, because you are using the actual database you'll also see in production.

    any*: Some of the commercial variants are either huge or take a long time to start up, but Postgres works great.