As simple as PostgreSQLContainer postgresql = new PostgreSQLContainer() GenericContainer redis = new GenericContainer("redis:3") .withExposedPorts(6379) @bsideup
• Fix local Docker Compose on Windows Sep, 2018 @bsideup new DockerComposeContainer(new File("docker-compose.yml")) .withExposedService("redis_1", REDIS_PORT) .withExposedService("db_1", 3306) .withLocalCompose(true);
1.10.x • JUnit 5 support Nov, 2018 @bsideup @Testcontainers class MyTestcontainersTests { // will be shared between test methods @Container static final MySQLContainer MYSQL_CONTAINER = new MySQLContainer(); // will be started before and stopped after each test method @Container PostgreSQLContainer postgresqlContainer = new PostgreSQLContainer() .withDatabaseName("foo") .withUsername("foo") .withPassword(“secret"); @Test void test() { assertTrue(MYSQL_CONTAINER.isRunning()); assertTrue(postgresqlContainer.isRunning()); } }
public class KafkaContainer extends GenericContainer {} public class GenericContainer> /* */ {} https://youtrack.jetbrains.com/issue/KT-17186 https://stackoverflow.com/questions/39163749/how-to-use-a-java-self-bounded-class-in-scala @bsideup
❌ Hard to maintain ❌ Does not work with Kotlin/Scala ❌ Externally mutable objects ❌ “setX” isn’t supported, only “withX” (think collections) ❌ No imperative “if-else” with the fluent style @bsideup
✓ Super easy to maintain ✓ Works with any JVM language ✓ “Controllable mutability” - no modifications outside of “initialize” ✓ Void-retuning “setX” can easily be used @bsideup
✓ Super easy to maintain ✓ Works with any JVM language ✓ “Controllable mutability” - no modifications outside of “initialize” ✓ Void-retuning “setX” can easily be used ✓ Can use “if-else” @bsideup
✓ Ultra-fast ITDD (Integration Test Driven Development) ✓ Minimal effort for the users ✓ Works for most of the containers ✓ Eventually cleanups stale containers (unlike Docker Compose) @bsideup
✓ Ultra-fast ITDD (Integration Test Driven Development) ✓ Minimal effort for the users ✓ Works for most of the containers ✓ Eventually cleanups stale containers (unlike Docker Compose) ✓ Alpha version is available NOW @bsideup
Takeaways • https://testcontainers.org • Works on Linux, Mac and Windows • …including CIs like Jenkins, Travis, CircleCI, GH Actions, Azure Pipelines, …
• Provides a great balance between flexibility, usability, speed and features @bsideup