testcontainers / testcontainers/testcontainers-java

Restart the tc_initscript before each test

Open
#3,239 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Hi,

I successfully set up TestContainers in a quarkus application with this kind of configuration:

%test.quarkus.datasource.url=jdbc:tc:postgresql:11:///dbname?TC_INITSCRIPT=file:src/test/resources/init.sql

However in some tests I delete rows; and I'd like that each test start with the same database state.

Is there any way to force TestContainers to re-run the initscript before each test, or even each test class?

PS: I could probably init the containers myself from test classes to achieve it; however I set up 3 different databases and it would need lot of boilerplate code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Testcontainers handling of the TC_INITSCRIPT option and its container lifecycle during JUnit tests. Define whether rerunning the script per test or test class is supported, and consider how the behavior would work for multiple configured databases without requiring setup boilerplate.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, postgresql
Domain
databases, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.