New in Testcontainers – Dec 2021

The world moves incredibly fast and the software development ecosystem even faster. This week, for example, a lot of spotlights are on the AWS Reinvent event, which always delivers a ton of interesting content and a myriad of announcements and releases of interesting cloud technologies.

In this digest, we’d like to point out a few notable events in the Testcontainers ecosystem, both around the libraries themselves and other materials making your integration tests easier to start with, faster, or more reliable.

Releases

The last few months brought had a long-awaited release of the flagship Testcontainers library – testcontainers-java. Actually, there were 2 releases: 1.16.1 and 1.16.2 in rapid succession and both brought a ton of improvements. In this article we’d like to highlight one in particular which relates back to the core value proposition — easier usage of databases for your integration tests.

These last releases have a much improved Oracle database support that relies on the Express Edition of Oracle Database. With the help of Gerald Venzl, the maintainer of the Docker images for Oracle Database XE, Testcontainers users can now use the current 21.3 release of XE with the elegance and simplicity of a provided Testcontainers module:

OracleContainer container = new OracleContainer("gvenzl/oracle-xe:21.3.0-slim")
                .withDatabaseName("isnt")
                .withUsername("this")
                .withPassword("amazing?");
container.start(); 

Another significant release in the Testcontainers ecosystem was, of course, the announcement of the Testcontainers Cloud, which can speed up, simplify your integration tests and bring them to the platforms where it’s complicated to run workloads that use Docker. You can still join the private beta stage and see how it helps your setup by filling the application form.

On top of that, there was another notable release in the same timeframe: testcontainers-go v0.12.0. And we’re especially happy to highlight this, since having a polyglot ecosystem is one of the major benefits of Testcontainers — all your applications equally deserve great integration tests.

Among a number of improvements and bugfixes 0.12 improved documentation quite a bit and added support for running tests with Testcontainers Cloud.

Larger ecosystem

One very interesting detail is that Testcontainers not only influences the integration testing landscape but also the larger community of JVM languages as a whole. A recent release of Kotlin has one Testcontainers-related improvement: “inferring a type argument based only on the upper bounds of the corresponding type parameter if it is a recursive generic by default.”

If it sounds complex, this helps using code with recursive generics patterns, which often occur in various builder patterns (and which is featured in Joshua Bloch’s Effective Java book), for example in testcontainers-java:

public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>> 
extends GenericContainer<SELF> implements LinkableContainer ...

Now in Kotlin 1.60 you can use it without needing any <nothing>-s or apply in the code, just as you’d expect if you’re coming from Java:

// before
val containerA = PostgreSQLContainer<nothing>(DockerImageName.parse("postgres:13-alpine")).apply {
    withDatabaseName("db")
    ... 
}
// after
val containerB = PostgreSQLContainer(DockerImageName.parse("name"))
    .withDatabaseName("db")
...

It’s a great improvement to readability and hopefully will help Kotlin projects using Testcontainers to be even less verbose.

Community

Talking about the helpful materials in the larger Testcontainers community, one tutorial we’d like to highlight is Philip Riecks’ article about using LocalStack for integration tests of applications that use AWS services.

Spring Boot Integration Tests With AWS Services Using LocalStack

It was recently updated to use the modern versions of all dependencies and with e:Invent happening it’s only fitting to talk about testing apps depending on cloud services.

Another notable article that we saw being helpful is by Sandra Parsick who demonstrates a very important feature of testing Spring Boot apps — how to use @DynamicPropertySource to dynamically configure data sources and other parameters you obtain from running containers without depending on fixed port numbers for your tests.

Using Testcontainers in Spring Boot Tests For Database Integration Tests

Sharing tutorials and helpful examples like that is one of the ways you can help the community and your peers without directly contributing code to the OSS projects you love.

Testcontainers Live

Recently we started regular live streams with interesting guests in the Testcontainers community where we talk about integration tests, reliability of releases, best practices in software development, programming languages and ecosystems, and anything else we find interesting.

We sincerely hope you’ll also find these exciting and full of insight.

Here’s the video of the first episode available on YouTube: Testcontainers Live #0: What’s new and cool in the integration tests lands?

And if you’d like to join us live — checkout the next episode where we’ll look at some of the more common issues with how developers use Testcontainers we see in the community:

Tune in to the stream on Wednesday and say hi!


This is it for today, as you may have noticed, this entry is not for a particular time frame, but the following ones will mostly cover things between New in Testcontainers installments. In this article we highlighted some notable releases, interesting pieces of content, and video materials that appeared in the Testcontainers ecosystem in recent times.