Skip to content

Commit 46e4c4b

Browse files
committed
docs: add JUnit-style example test to k6 module docs
1 parent 5323acd commit 46e4c4b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

docs/modules/k6.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ Testcontainers module for [k6](https://registry.hub.docker.com/r/grafana/k6).
1111

1212
## Basic script execution
1313

14-
Execute a simple k6 test script, `test.js`, with commandline options and injected script variable.
14+
The following example shows a typical JUnit 5 test that runs a k6 script inside a container, waits for the run to finish, and asserts on the output.
15+
16+
<!--codeinclude-->
17+
[Running a k6 script in a JUnit test](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:standard_k6_test
18+
<!--/codeinclude-->
19+
20+
The test above uses a simple k6 script, `test.js`, with command line options and an injected script variable.
1521

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

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

modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class K6ContainerTests {
1212

1313
@Test
1414
void k6StandardTest() throws Exception {
15+
// standard_k6_test {
1516
try (
1617
// standard_k6 {
1718
K6Container container = new K6Container("grafana/k6:0.49.0")
@@ -37,5 +38,6 @@ void k6StandardTest() throws Exception {
3738

3839
assertThat(container.getLogs()).contains("k6 tests are cool!");
3940
}
41+
// }
4042
}
4143
}

0 commit comments

Comments
 (0)