Populate a database with TestContainers in a SpringBoot integration test
The easiest way is to use JdbcDatabaseContainer::withInitScript Advantage of this solution is that script is run before Spring Application Context loads (at least when it is in a static block) and the code is quite simple. Example: static { postgreSQLContainer = new PostgreSQLContainer(“postgres:9.6.8”) .withDatabaseName(“integration-tests-db”) .withUsername(“sa”) .withPassword(“sa”); postgreSQLContainer .withInitScript(“some/location/on/classpath/someScript.sql”); postgreSQLContainer.start(); } JdbcDatabaseContainer is superclass of PostgreSQLContainer … Read more