Reputation: 10585
I am using JUnit5 + Testcontainers.
I see there are Testcontainer modules such as these: https://github.com/testcontainers/testcontainers-java/tree/main/modules
I would like to build my own Testcontainers custom module.
Is there a way for developers to build their own?
Upvotes: 1
Views: 522
Reputation: 10218
Yes, you can extend the GenericContainer
class. By overriding methods like containerIsStarted
or adding your own methods, you can customize the container's behavior.
Have a look at how these modules are implemented, e.g., the MongoDB one. It overrides containerIsStarted
to initialize a replica set:
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo, boolean reused) {
if (reused && isReplicationSetAlreadyInitialized()) {
log.debug("Replica set already initialized.");
} else {
initReplicaSet();
}
}
Upvotes: 2