Skip to content

k6 Module


This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See our contributing guidelines for more information on our incubating modules policy.

Testcontainers module for k6.

k6 is an extensible reliability testing tool built for developer happiness.

Basic script execution

Execute a simple k6 test script, test.js, with commandline options and injected script variable.

Create a simple k6 test script to be executed as part of your tests:

K6Container container = new K6Container("grafana/k6:0.49.0")
    .withScriptVar("MY_SCRIPT_VAR", "are cool!")
    .withScriptVar("AN_UNUSED_VAR", "unused")
    .withCmdOptions("--quiet", "--no-usage-report")
// The most basic of k6 scripts.
export default function(){
    console.log(`k6 tests ${__ENV.MY_SCRIPT_VAR}`)

Adding this module to your project dependencies

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

testImplementation "org.testcontainers:k6:1.20.0"