Integration Testing
A common Paramixel pattern is:
- create resources in
Lifecycle.before - store them with
Context#setAttachment(...) - use them from descendants via
findAttachment(...)orfindContext(...) - release them in
Lifecycle.after
Example shape
Action action = Lifecycle.of(
"environment",
Direct.of("before", context -> context.setAttachment(startEnvironment())),
Parallel.of(
"tests",
Direct.of("check A", context -> {
Environment env = context.findAttachment(1)
.flatMap(a -> a.to(Environment.class))
.orElseThrow();
}),
Direct.of("check B", context -> {})),
Direct.of("after", context -> stopEnvironment(context.removeAttachment())));
Real examples
See:
examples/testcontainers/kafka/KafkaExample.javaexamples/testcontainers/mongodb/MongoDBExample.javaexamples/testcontainers/nginx/NginxExample.java
These examples use Lifecycle, attachments, and Cleanup to manage Testcontainers resources.