Skip to content

Commit

Permalink
Clarify docs for #4036
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed May 27, 2024
1 parent 256318c commit f4cd449
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions documentation/docs/extensions/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ With *System Environment Extension* you can simulate how the System Environment
Kotest provides some extension functions that provides a System Environment in a specific scope:

```kotlin
withEnvironment("FooKey", "BarValue") {
System.getenv("FooKey") shouldBe "BarValue" // System environment overridden!
test("foo") {
withEnvironment("FooKey", "BarValue") {
System.getenv("FooKey") shouldBe "BarValue" // System environment overridden!
}
}
```

:::info
To use `withEnvironment` with JDK17 you need to add `--add-opens=java.base/java.util=ALL-UNNAMED` to the arguments for the JVM that runs the tests.
To use `withEnvironment` with JDK17+ you need to add `--add-opens=java.base/java.util=ALL-UNNAMED` to the arguments for the JVM that runs the tests.

If you run tests with gradle, you can add the following to your `build.gradle.kts`:

Expand All @@ -52,8 +54,10 @@ tasks.withType<Test>().configureEach {
You can also use multiple values in this extension, through a map or list of pairs.

```kotlin
withEnvironment(mapOf("FooKey" to "BarValue", "BarKey" to "FooValue")) {
// Use FooKey and BarKey
test("foo") {
withEnvironment(mapOf("FooKey" to "BarValue", "BarKey" to "FooValue")) {
// Use FooKey and BarKey
}
}
```

Expand Down

0 comments on commit f4cd449

Please sign in to comment.