Skip to content

Hashicorp Vault Module

Testcontainers module for Vault. Vault is a tool for managing secrets. More information on Vault here.

Usage example

Running Vault in your Junit tests is easily done with an @Rule or @ClassRule such as the following:

public class SomeTest {

    public static VaultContainer vaultContainer = new VaultContainer<>()
            .withSecretInVault("secret/testing", "top_secret=password1","db_password=dbpassword1");

    public void someTestMethod() {
       //interact with Vault via the container's host, port and Vault token. 

       //There are many integration clients for Vault so let's just define a general one here:
       VaultClient client = new VaultClient(

       List<String> secrets = client.readSecret("secret/testing");


Why Vault in Junit tests?

With the increasing popularity of Vault and secret management, applications are now needing to source secrets from Vault. This can prove challenging in the development phase without a running Vault instance readily on hand. This library aims to solve your apps integration testing with Vault. You can also use it to test how your application behaves with Vault by writing different test scenarios in Junit.

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

testImplementation "org.testcontainers:vault:1.17.3"



Copyright (c) 2017 Capital One Services, LLC and other authors.

See AUTHORS for contributors.