I'am trying to create isolated test env using TestContainers (for database - postgresql and external services - for example authorising service). My question is, how can i set path in application.yml
/application.properties
to these external services? With db is easy i just need to use "jdbc:tc:postgresql:14.5:///dbtests"
, to create containers with my services i use GenericContainer<?>
and ports are different every start. TestContainers (except db) are initialized in external class.
You always have to think about how you can inject the dynamic connections URLs into your system-under-test. How you can do is very specific to your application. If you create objects yourself, you can simply to construction dependency injection, like in this example.
For frameworks, there is generally a framework-specific approach. As Eddú already mentioned in the comments, Spring-Boot allows the usage of DynamicPropertySource
.