Skip to content
/ pgtest Public

Example postgres unit tests with Testcontainers

Notifications You must be signed in to change notification settings

mbjones/pgtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgtest

An example repository showing how to use Testcontainers to use stateful container dependencies in unit tests. In this case:

  • Set up a postgresql database
  • Use Flyway to initialize the database
  • Run a SQL select test against the database

I tried to keep the dependencies to a minimum, and some of these could be replaced with other choices:

  • Testcontainers
  • Postgresql JDBC driver
  • FlywayDB (optional, could be replaced)
  • HikariCP connection pool (optional, could be replaced)

Apple Silicon on Rancher Desktop

For M1, M2, and M3 macs, testcontainers has trouble launching using Rancher Desktop, but there is a RD workaround by setting an environment variable. First, run:

$ export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show rd0 | awk '/inet / {sub("/.*",""); print $2}')

Then you can run the tests with:

$ mvn test

About

Example postgres unit tests with Testcontainers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published