Annotation Type DynamicPropertySource


@Documented @Retention(CLASS) @Target(METHOD) public @interface DynamicPropertySource

Marks a static method of a test class that adds settings whose values are only known when the test starts -- the port of a database container, a temporary directory:

@DynamicPropertySource
static void database(DynamicPropertyRegistry registry) {
    registry.add("cn1.datasource.url", () -> container.getJdbcUrl());
}

The build calls the method from the test's generated context, so it must be static, take one DynamicPropertyRegistry and be visible from the test's package. The values are read once, when the application starts, and win over the test annotation's properties. A class with such a method gets an application of its own rather than sharing one with other test classes, because what it adds is not known until it runs.