|
1 | 1 | # k6 Module |
2 | 2 |
|
3 | | -!!! note |
4 | | - This module is INCUBATING. |
5 | | - 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. |
6 | | - See [our contributing guidelines](/contributing/#incubating-modules) for more information on our incubating modules policy. |
| 3 | +!!! note |
| 4 | +This module is INCUBATING. |
| 5 | +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. |
| 6 | +See [our contributing guidelines](/contributing/#incubating-modules) for more information on our incubating modules policy. |
7 | 7 |
|
8 | 8 | Testcontainers module for [k6](https://registry.hub.docker.com/r/grafana/k6). |
9 | | - |
10 | 9 | [k6](https://k6.io/) is an extensible reliability testing tool built for developer happiness. |
11 | 10 |
|
12 | | -## Basic script execution |
13 | | - |
14 | | -Execute a simple k6 test script, `test.js`, with commandline options and injected script variable. |
15 | | - |
16 | | -Create a simple k6 test script to be executed as part of your tests: |
17 | | - |
18 | | -<!--codeinclude--> |
19 | | -[Setup the container](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:standard_k6 |
20 | | -[Content of `scripts/test.js`](../../modules/k6/src/test/resources/scripts/test.js) inside_block:access_script_vars |
21 | | -<!--/codeinclude--> |
22 | | - |
23 | | -## Adding this module to your project dependencies |
24 | | - |
25 | | -Add the following dependency to your `pom.xml`/`build.gradle` file: |
26 | | - |
27 | | -=== "Gradle" |
28 | | - ```groovy |
29 | | - testImplementation "org.testcontainers:testcontainers-k6:{{latest_version}}" |
30 | | - ``` |
31 | | -=== "Maven" |
32 | | - ```xml |
33 | | - <dependency> |
34 | | - <groupId>org.testcontainers</groupId> |
35 | | - <artifactId>testcontainers-k6</artifactId> |
36 | | - <version>{{latest_version}}</version> |
37 | | - <scope>test</scope> |
38 | | - </dependency> |
39 | | - ``` |
| 11 | +## Usage |
| 12 | + |
| 13 | +Here is a basic example of how to create and start a K6 container: |
| 14 | + |
| 15 | +```java |
| 16 | +try ( |
| 17 | + // k6_container { |
| 18 | + K6Container container = new K6Container(DockerImageName.parse("grafana/k6:0.49.0")) |
| 19 | + .withTestScript("scripts/test.js") |
| 20 | + .withScriptVar("MY_VAR", "hello") |
| 21 | + // } |
| 22 | +) { |
| 23 | + container.start(); |
| 24 | + // Perform assertions based on logs or container state |
| 25 | +} |
0 commit comments