preloader

Developing with Testcontainers

🗓️ Last updated on June 17, 2024 | 3 | Improve this page

Overview

This guide will provide you with pointers on how to embed Microcks into your unit tests with the help of Testcontainers . The project now provides official modules for Testcontainers via a partenership with AtomicJar , the company behind this fantastic library!

You’ll learn how to automatically launch and shut down Microcks’ instances so that you can easily test your API clients and API contracts. You can find information on the official module on Testcontainers Microcks page .

As of today, we provide support for following languages:

  • Java ☕️ - starting from Java 8 to latest releases - via a library available on Maven Central ,
  • NodeJS / Typescript - via a Javascript library with types available on NPM ,
  • Golang - still experimental as Testcontainers Go has not yet the feature partity with other languages - via a library dsitributed via our GitHub.

Let’s go 🧊

1. Java support

Our Testcontainers module for Java is io.github.microcks:microcks-testcontainers, you easily add it to your Maven or Gradle powered project.

The library is making usage of our Uber distribution and you can simply start Microcks that way:

MicrocksContainer microcks = new MicrocksContainer(
      DockerImageName.parse("quay.io/microcks/microcks-uber:1.9.0"));
microcks.start();

See our microcks-testcontainers-java repository for full details.

Spring Boot integration

Microcks Testcontainers can be easily integrated in a Spring Boot application using Spring Boot Developer Tools so that when running in test mode, Microcks can be wired into your application to provide mocks for your dependencies.

See our demo application for Spring Boot 🍃

Quarkus integration

Microcks Testcontainers has also being extended to provide a Quarkus Dev Service . That way Microcks can be automatically started, configured and wxired to your application when starting in dev:mode.

See our microcks-quarkus repository for full details as well asour demo application for Quarkus .

2. NodeJS support

Our Testcontainers module for Javscript is @microcks/microcks-testcontainers, you easily add it to your NPM or Yarn powered project.

The library is making usage of our Uber distribution and you can simply start Microcks that way:

const container = await new MicrocksContainer("quay.io/microcks/microcks-uber:1.9.0").start();

See our microcks-testcontainers-node repository for full details and our full demo application using NestJS

3. Golang support

Our Testcontainers module for Javscript is github.com/testcontainers/testcontainers-go, you easily add it to your Go mod file.

The library is making usage of our Uber distribution and you can simply start Microcks that way:

microcksContainer, err := microcks.RunContainer(ctx, testcontainers.WithImage("quay.io/microcks/microcks-uber:1.9.1"))

See our microcks-testcontainers-go repository for full details and our full demo application

Wrap-up

Testcontainers + Microcks is really a powerful combo for simplifying the write-up of robust unit or integration tests where the fixtures can be directly deduced from specifications. And the best thing is that this tooling is totally independent of your technology stack! You can use them for NodeJS, Go, Java, Ruby development, or whatever!

We don’t provide a built-in module for the stack you’re using? Poke us on Discord , we’d really like to get your suggestion and help to get this rolling!

If you want to learn more about the underlying thoughts and alternatives you may have if you’re not running Testcontainers, here’s below a set of blog posts writtent during our explorations:

Still Didn’t Find Your Answer?

Join our community and get the help you need. Engage with other members, ask questions, and share knowledge to resolve your queries and expand your understanding.

Join the community