Skip to content

Make use of @DynamicPropertySource in our integration tests #16886

Closed
@wilkinsona

Description

@wilkinsona

There's a bit of ceremony involved at the moment:

@Testcontainers
@ContextConfiguration(initializers = DataRedisTestIntegrationTests.Initializer.class)
@DataRedisTest
public class DataRedisTestIntegrationTests {

    @Container
    public static RedisContainer redis = new RedisContainer();

    // …

    static class Initializer
            implements ApplicationContextInitializer<ConfigurableApplicationContext> {

        @Override
        public void initialize(
                ConfigurableApplicationContext configurableApplicationContext) {
            TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort())
                    .applyTo(configurableApplicationContext.getEnvironment());
        }

    }

It would be nice to be able to do something like this instead:

@Testcontainers
@DataRedisTest
public class DataRedisTestIntegrationTests {

    @Container
    @MapPortToProperty("spring.redis.port")
    public static RedisContainer redis = new RedisContainer();

A few thoughts:

  • The examples above are JUnit 5. We'd need to consider JUnit 4 as well
  • The lifecycle ordering will need to be right so that the container's port is available before the context refreshes
  • Setting the port will affect context caching

/cc @bsideup

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by anothertype: taskA general task

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions