testcontainers / testcontainers-java-spring-boot-quickstart

Testcontainers QuickStarts
MIT License
51 stars 26 forks source link

How do we change the default Database name or username for Container in junit test in Junit5? #11

Open ShubhamShekhar1996 opened 1 year ago

ShubhamShekhar1996 commented 1 year ago

How do we change the default Database name or username and container port for Container in junit test in Junit5? By default it takes everything as test. Junit5, Spring boot- 3.1.3

kauanmocelin commented 2 days ago

You can do it like this to change default values for database name, username and password:

private static final PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>(DockerImageName.parse(
    "postgres:16-alpine"
))
    .withDatabaseName("")
    .withUsername("")
    .withPassword("");

Ports on host are generated randomly by design. You can get more information in the official documentation: Exposing container ports to the host