Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions docs/modules/k6.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
# k6 Module

!!! note
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](/contributing/#incubating-modules) for more information on our incubating modules policy.
!!! note
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](/contributing/#incubating-modules) for more information on our incubating modules policy.

Testcontainers module for [k6](https://registry.hub.docker.com/r/grafana/k6).

[k6](https://k6.io/) 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:

<!--codeinclude-->
[Setup the container](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:standard_k6
[Content of `scripts/test.js`](../../modules/k6/src/test/resources/scripts/test.js) inside_block:access_script_vars
<!--/codeinclude-->

## Adding this module to your project dependencies

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

=== "Gradle"
```groovy
testImplementation "org.testcontainers:testcontainers-k6:{{latest_version}}"
```
=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-k6</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
```
## Usage

Here is a basic example of how to create and start a K6 container:

```java
try (
// k6_container {
K6Container container = new K6Container(DockerImageName.parse("grafana/k6:0.49.0"))
.withTestScript("scripts/test.js")
.withScriptVar("MY_VAR", "hello")
// }
) {
container.start();
// Perform assertions based on logs or container state
}