Collects test properties whose values are known only when the tests run, such as the port of a server or a temporary directory.
A test cannot write such values into properties:, which is fixed when
springBootTest is called. Instead it registers a function per
property; the application calls it whenever it reads the property, so
it sees the value of the moment. The registry is handed to the
dynamicProperties: callback of springBootTest, or to a
@DynamicPropertySource() method of a test class. The values win over
every other property source.
late HttpServer server;
// Declared before springBootTest, so the server is up when it starts.
setUpAll(() async => server = await HttpServer.bind('localhost', 0));
final app = springBootTest(
springApplication,
dynamicProperties: (registry) => registry
..add('catalog.url', () => 'http://localhost:${server.port}'),
);
Spring (Java):
@DynamicPropertySource
static void properties(DynamicPropertyRegistry registry) {
registry.add("catalog.url", server::baseUrl);
}
- Implementers
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
String name, Object? valueSupplier()) → void -
Adds the property
name.valueSupplieris called each time the property is read, so it returns the current value; adding the same name again replaces the supplier. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited