I have problem with creating external configuration for my test classes. Right now my redis related tests have to have a companion object inside
@Testcontainers
@TestPropertySource("classpath:/application-test.properties")
@SpringBootTest
class RedisRelatedTest {
companion object {
@Container
val container = GenericContainer<Nothing>("redis:5.0.7-alpine")
.apply { withExposedPorts(6379) }
@JvmStatic
@DynamicPropertySource
fun properties(registry: DynamicPropertyRegistry) {
registry.add("spring.redis.host", container::getHost);
registry.add("spring.redis.port", container::getFirstMappedPort);
}
}
... some tesitng
}
I'd like to move it somewhere outside and and use some one liner to include it but I can't find a way that works. I've created a RedisConfig class with its companion object but @Import(RedisConfig::class) or @Import(RedisConfig.Congig::class) is completely ignored.