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