# Running Integration Tests with Testcontainers
Testcontainers (opens new window) is a popular library for integration testing, designed to simplify the setup and management of test environments. It enables running real services in isolated Docker containers, making it easy to create consistent testing scenarios both locally and in CI/CD pipelines.
With Testcontainers, you can run the typesense/typesense Docker image using your preferred programming language. You can achieve this via the Generic Container API, offering full control and flexibility, or leverage a prebuilt module, which streamlines container configuration and setup, saving time and effort.
# Java
First, let's import the dependency using Gradle or Maven.
Using Gradle:
testImplementation "org.testcontainers:typesense:1.20.4"
or Maven:
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>typesense</artifactId>
<version>1.20.4</version>
<scope>test</scope>
</dependency>
Now, let's write a test using TypesenseContainer, which will start the container.
Then, configure Typesense's client to connect with the container.
try (
TypesenseContainer typesense = new TypesenseContainer("typesense/typesense:27.1")
) {
typesense.start();
List<Node> nodes = Collections.singletonList(
new Node("http", typesense.getHost(), typesense.getHttpPort())
);
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(5), typesense.getApiKey());
Client client = new Client(configuration);
}
There is also integration with JUnit 4, JUnit 5 and Spock test libraries. For more information about Testcontainers for Java, check the docs (opens new window).
This documentation site is open source. Found an issue? Edit this page (opens new window) and send us a Pull Request.
For AI Agents: View an easy-to-parse, token-efficient
Markdown version of this page. You can also replace
.html with .md in any docs URL. For paths ending in /, append
README.md to the path.