4 ms·
I always go further and use the same database for my tests e.g. use postgres rather than H2. It is easy enough to setup and tear down using docker.
by heurisko 5y ago
I always go further and use the same database for my tests e.g. use postgres rather than H2.
It is easy enough to setup and tear down using docker.
- danielheath 5y agoAfter a bug slipped through because of it, I switched CI to run the same point release of the database, and validate that the schema is identical to production.
- noisy_boy 5y agoThat is a good idea. Though H2 supports specifying the database dialect so it is a pretty close and usually quicker approximation.
- heurisko 5y agoIf speed is one of the things holding you back from testing with the native database, running the database data on a tmpfs mountpoint is worth looking at. https://vladmihalcea.com/how-to-run-integration-tests-at-warp-speed-with-docker-and-tmpfs/ https://vladmihalcea.com/how-to-run-integration-tests-at-war...
- noisy_boy 5y agoFor me, it is more of zero setup while getting most of the benefits which is "good enough" (tmpfs works great but every new developer would need to do this + setup/permissions needed for docker + differences between Windows/Linux and/or desktop vs CI host etc).
- heurisko 5y agoIt looks like tmpfs is Linux-only feature. Otherwise I have a single docker-compose.yml file that sets up postgres using "Docker for Desktop" on Mac and Windows and works natively on Linux. CI (Linux) uses the same docker-compose.yml. I haven't used docker in production, but it has proved very useful in test.
- jmchuster 5y agoand now as easy as adding `@AutoConfigureEmbeddedDatabase` https://github.com/zonkyio/embedded-database-spring-test https://github.com/zonkyio/embedded-database-spring-test also helps with having it verify all your database migrations as well