2

When using reusable container with init script, it runs the script every time the test start even though same DB is being reused. In init script I have create and insert statements so every time I run the test, it tries to execute the sql statements and fails with table already exists.

1 Answers1

0

You can execute init scripts manually by using testcontainers class JdbcDatabaseDelegate instead of calling for postgresContainer.withInitScripts() before the startup.

For example:

JdbcDatabaseDelegate delegate = new JdbcDatabaseDelegate(postgresContainer, "");
ScriptUtils.runInitScript(delegate, sqlScriptFilePath));