By Hai Nguyen

Why We Open Sourced Spring TestContainers Beyond FlowInquiry

Learn why FlowInquiry open sourced Spring TestContainers—an annotation-based library that simplifies integration testing for PostgreSQL, MySQL, Ollama, and more in Spring Boot.

Why We Open Source Our Tools Beyond FlowInquiry

At FlowInquiry, we build tools to solve real problems. Some of these tools are internal systems that support key features of our product. Others are general-purpose utilities that we realized could help developers outside our team.

Rather than keeping these tools private, we’ve begun open-sourcing them—starting with Spring TestContainers, a library that simplifies integration testing using Docker containers in Spring and Spring Boot applications.


Building for Reuse

As we developed FlowInquiry, we needed reliable ways to test external systems like databases, messaging queues, and AI models. Instead of writing boilerplate setup code for each test case, we created lightweight, annotation-based wrappers using the popular Testcontainers library. Over time, this evolved into a general-purpose solution: Spring TestContainers.

Spring TestContainers now works independently of the FlowInquiry product and is available as a standalone open source project. It’s designed to work in any Spring or Spring Boot application with minimal setup.


What Is Spring TestContainers?

Spring TestContainers is a Java library that wraps Testcontainers with a clean, annotation-driven API. It handles container lifecycles and auto-configures your Spring environment to connect to them. With it, you can write tests like this:

@SpringBootTest
@EnablePostgreSQL(version = "15")
class MyIntegrationTest {

    @Autowired
    DataSource dataSource;

    @Test
    void testDatabaseConnection() {
        // PostgreSQL container is automatically started and configured
    }
}

Key Features

  • ✅ Simple annotations like @EnablePostgreSQL, @EnableMySQL, @EnableOllamaContainer

  • ✅ Automatic container startup and teardown

  • ✅ Seamless Spring environment configuration

  • ✅ Works with JUnit 5

  • ✅ Compatible with Spring 6+ and Spring Boot 3+

Supported Containers (So Far)

Spring TestContainers currently provides first-class support for:

  • PostgreSQL

  • MySQL

  • Ollama (for running local LLMs like LLaMA, Mistral, Phi-3)

But the design is flexible. You can easily add support for more services by writing a custom container extension.

To learn how to add support for new containers, check out our guide: 👉 Writing a New Container Extension for Spring TestContainers

How Does It Compare to Spring Boot’s Native Testcontainers Support?

Starting in Spring Boot 3.1, the framework introduced native support for Testcontainers via the @ServiceConnection annotation. This allows you to define containers as beans and have Spring Boot manage their lifecycle and configuration.

While both approaches aim to simplify integration testing with containers, they differ in style and flexibility.

Spring Boot’s native approach is more programmatic. You define containers using @Bean methods and annotate them with @ServiceConnection. Spring TestContainers, on the other hand, favors a declarative, annotation-based style that works in both Spring and Spring Boot projects.

Here’s a side-by-side comparison:

Feature Spring TestContainers Spring Boot @ServiceConnection
Configuration style Annotation-based Bean-based
Verbosity Very concise More verbose
Supported Spring versions Spring 6+, Spring Boot 3+ Spring Boot 3.1+ only
Flexibility Fixed set of supported annotations Full programmatic control
Built-in optimizations Yes — includes defaults (e.g., Ollama setup) No — developers must configure manually
Ideal for Quick setup and readable tests Using container types not yet supported by Spring TestContainers

When to Use What

Use Spring TestContainers if you:

  • Prefer minimal boilerplate and concise setup
  • Like using annotations at the class level without defining beans
  • Want a solution that works in both Spring and Spring Boot projects
  • Are testing common services like PostgreSQL, MySQL, or Ollama with opinionated defaults (e.g., container reuse, AI model caching)

Use Spring Boot’s @ServiceConnection if you:

  • Prefer configuring containers as beans
  • Need to support a wider range of Testcontainers modules not yet handled by Spring TestContainers

Using It for AI Testing at FlowInquiry

One of our internal use cases was testing AI prompt responses using Ollama. We wanted to test real LLM interactions as part of our CI pipelines—without relying on third-party cloud APIs. That’s where Spring TestContainers for Ollama came in.

By annotating our test classes with @EnableOllamaContainer, we spin up a Docker container running an Ollama LLM, like llama3:latest, and inject a fully configured ChatClient for use in our tests.

Example:

@SpringBootTest
@EnableOllamaContainer(model = "llama3:latest")
class AiPromptTest {

    @Autowired
    ChatClient.Builder chatClientBuilder;

    @Test
    void testSimplePrompt() {
        var client = chatClientBuilder.build();
        var result = client.prompt().user("What is 2 + 2?").call().content();
        assertTrue(result.contains("4"));
    }
}

This approach helped us build more confidence in our AI workflows, especially for customer-facing features like ticket insights and auto-summarization.

Why We Open Source These Tools

We’ve built FlowInquiry on top of many great open source projects—from Spring Boot to Testcontainers, from Next.js to PostgreSQL. Contributing back is part of how we operate.

Open-sourcing Spring TestContainers helps:

  • Improve the quality of our internal tools

  • Reduce maintenance by enabling reuse across projects

  • Engage with other developers facing similar challenges

  • Give back to the same open source community we benefit from

Try It Out

Spring TestContainers is fully open source and available on GitHub: 🔗 https://github.com/flowinquiry/spring-testcontainers

You can use it today in any Spring project—whether or not you use FlowInquiry.

Conclusion

We believe open source isn’t just about code—it’s about sharing ideas that make engineering better. When we generalize our internal work into tools like Spring TestContainers, we’re not just helping ourselves—we’re contributing to a broader community.

If you’re building Spring applications and want cleaner integration testing, we hope you find Spring TestContainers useful.

And if you’re using FlowInquiry, know that many of the tools behind it are available to you too.