# Testcontainers

Testcontainers is an open-source framework that provides disposable, lightweight instances of databases, message brokers, web browsers, or virtually anything that can run in a Docker container. With Testcontainers, you can write tests that depend on the same services used in production, without the need for mocks or in-memory services. Figure 1 shows how all *My Service* dependencies can be replaced with the testcontainers.

<figure><img src="/files/cyT1yPmpHKVCTeN8XlDJ" alt=""><figcaption><p>Service dependencies as testcontainers</p></figcaption></figure>

## Testcontainers workflow <a href="#testcontainers-testcontainersworkflow" id="testcontainers-testcontainersworkflow"></a>

You can use Testcontainers with any testing library you are already familiar with. A typical Testcontainers-based integration test works as follows:

* **Before Test execution:** Start your required services (databases, messaging systems etc.) as Docker containers using the Testcontainers API. Once the required containers start, configure or update your application configuration to use these containerized services and optionally initialize data needed for the test.
* **During Test execution:** Your tests run using these containerized services.
* **After Test execution:** Testcontainers takes care of destroying containers irrespective

<figure><img src="/files/B56Jrl0MkUuvcAQOFz5P" alt=""><figcaption><p>Testcontainers workflow</p></figcaption></figure>

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.leapwise.co/backend-handbook/development-practices/testing-guidelines/testing-frameworks/testcontainers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
