Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I load properties from application file for Testcontainer?

Currently, I am using Testcontainer to implement integration testing for database in spring boot. How do I init the Testcontainer with the application.yml. I don’t want to use @DynamicPropertySource.

public static PostgreSQLContainer container = new PostgreSQLContainer("postgres:12")
spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/db
    username: user
    password: password

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can simply add tc to you spring.datasource.url property.

spring:
  datasource:
    driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
    url: jdbc:tc:postgresql:12:///db?TC_TMPFS=/testtmpfs:rw
    username: user
    password: password

I prefer not to use application.yaml just create application-test.yaml and override default one. You can check https://www.testcontainers.org/modules/databases/jdbc/.

Also you can override with @testpropertysource annotation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading