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.
Asked
Active
Viewed 271 times
2
-
Did you manage to find an answer? – OroshiX Sep 12 '22 at 12:43
1 Answers
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));

Kruz Uzdyak
- 16
- 2