Container class final

Marks a static field that holds a container the tests need: it starts once, before the class's context, and is removed after the last test.

The field's value is a GenericContainer or a module such as PostgresContainer. It must be static (the context starts before the test class is created, and one container serves all its tests) and public; the containers start in the order of the fields. Add ServiceConnection to wire the application to it, or read its host and mappedPort(...) in a @DynamicPropertySource method, which runs after the containers started.

@Container()
static final redis = GenericContainer('redis:7.4-alpine')
    .withExposedPorts([6379])
    .waitingFor(Wait.forLogMessage('Ready to accept connections'));

@DynamicPropertySource()
static void redisUrl(DynamicPropertyRegistry registry) => registry.add(
  'cache.redis.url',
  () => 'redis://${redis.host}:${redis.mappedPort(6379)}',
);

Spring (Java): Testcontainers' @Container, on a static field of a class with @Testcontainers. Instance fields (a container per test) are not supported: the context needs the container before the first test.

Constructors

Container()
Marks the field.
const

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

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