This a docker image based in the official Postgres 15.1 docker image tweaked for database testing.
It basically configure things like turning off write ahead log (fsync=off
) to make it faster. Notice that this can make the database more likely to be in an inconsistent state, if the case of a server crash. This is not a problem for database testing as we are more concerned with fast feedback and not about loosing data.
This is an alternative to H2, in memory SQLite and HyperSQL. You should consider this as it runs a real PostgreSQL server, that would be very close on what you have in production.
Check the file config.sh
for all the configurations.
References:
- https://stackoverflow.com/questions/9407442/optimise-postgresql-for-fast-testing
- http://michael.robellard.com/2015/07/dont-test-with-sqllite-when-you-use.html
- Do all schema setup (DDL) once before running the tests
- Run the schema setup (DDL), as the DB migration that would run in production
- Avoid DDL in each test, as that tent to be very slow
- Before each test, truncate the tables and put some seed data (DML), that should be quick
- Remember fasts tests are important, slow tests make you avoid refactoring code!
- Tweak
shared_buffers
- Tweak
work_mem