Testcontainers integration

Testcontainers for Java is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

By combining Testcontainers with Synthesized’s Test Data Kit (TDK), developers can populate any Testcontainers database with synthetically generated data, enabling rapid development of tests for logic which involves interaction with the database, while avoiding the need to develop and maintain huge amounts of code.

In order to do this one can use tdk-tc — a lightweight open sourced library which acts as a thin client for Synthesized TDK integrated with TestContainers.

Adding a dependency to tdk-tc

In order to use tdk-tc, find the most recent version of it on Maven Central, then include it in your project’s test dependencies using Maven or Gradle:



  <version>[version here]</version>

Using SynthesizedTDK class

The class io.synthesized.tdktc.SynthesizedTDK runs Synthesized TDK in a Docker container using Testcontainers internally.

A transformation can be run by calling transform method on an instance of SynthesizedTDK.

new SynthesizedTDK()
  // Use this method to alter container image name for the TDK-CLI container

  // Use this method to set license key in case you are using paid version of TDK-CLI

     //Input JdbcDatabaseContainer: empty database with schema
     //Output JdbcDatabaseContainer: output database with generated data
     //Workflow configuration in YAML format
          mode: "GENERATION"
          target_row_number: 10
        global_seed: 42
Both input and output containers must be on the same Testcontainers Network. SynthesizedTDK will run the TDK container on the same network also.

Am creation of two containers on the same network and starting them in parallel threads can look like this:

network = Network.newNetwork();
input = new PostgreSQLContainer<>("postgres:11.1")
output = new PostgreSQLContainer<>("postgres:11.1")
Startables.deepStart(input, output).join();

new SynthesizedTDK()

A good place to use SynthesizedTDK is in the @TestConfiguration of your Spring application, where you produce connections to the databases used during the test. The complete example of tdk-tc usage in a sample backend project is located here.