Hacker News new | ask | show | jobs
by dherikb 798 days ago
I am using TestContainers, what basically is able to run a Docker image of PostgreSQL, abstracting a lot of details. You can find a working example of this setup for integration tests using Go, testify and PosgreSQL here: https://github.com/dherik/ddd-golang-project

For Java services using MySQL, I was able to use just the H2 database (in-memory) many times. Does a decent job and it's very compatible with MySQL. If you try to avoid specific features from the databases, this in-memory database can do a decent (and fast) job running integration tests.

1 comments

The whole point of the article is to make it _fast_: can you share how fast it is to spin up your database with TestContainers?
Running an "mvnd clean package" on a very simple Spring Boot app having 4 different spring integration tests takes exactly 8 seconds on my m1 max.

This includes a full build of the application, postgres container startup and spring context startup.

Starting the postgres container seems be less than 2 seconds of those 8 seconds.

Is that fast enough?

From the article:

  However, on its own, template databases are not fast enough for our use case. The time it takes to create a new database from a template database is still too high for running thousands of tests:

  postgres=# CREATE DATABASE foo TEMPLATE contra;
  CREATE DATABASE
  Time: 1999.758 ms (00:02.000)
So no. They say this adds ~33 minutes to running their tests.
You can utilize all technics from article with the help of TestContainers. They will help with setting up DB and providing connection strings to running images