kotest / kotest-intellij-plugin

The official Kotest plugin for Intellij and Android Studio
Apache License 2.0
181 stars 25 forks source link

Use of "withEnvironment" extension function works when playing a spec class, but not an individual leaf #250

Closed zakhenry closed 1 year ago

zakhenry commented 1 year ago

for example with the following spec file:

/* 1 ▷ */ class FTest: DescribeSpec({

/* 2 ▷ */    describe("f") {

/* 3 ▷ */        it("f") {

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

                 }

             }

         })

if I play the line 1 the test passes, however if I play 2 or 3 the test fails with

Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @4f209819
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @4f209819

Kotest 5.5.2 and plugin version 1.3.68-IC-2023.1. I do have the following lines in build.gradle.kts

tasks.withType<Test>().configureEach {
    jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
}
Kantis commented 1 year ago

@zakhenry the Gradle configuration will only take effect when tests are invoked using Gradle.

When running an individual test, Kotest IntelliJ plugin will not invoke the test with Gradle, so the --add-opens is not applied.

Once https://github.com/kotest/kotest-intellij-plugin/issues/178 is fixed, you could configure IntelliJ to run tests with Gradle and this would work for individual tests as well.

sksamuel commented 1 year ago

Have you thought about using the kotest.properties setting ?

On Fri, 21 Apr 2023 at 17:23, Emil Kantis @.***> wrote:

@zakhenry https://github.com/zakhenry the Gradle configuration will only take effect when tests are invoked using Gradle.

When running an individual test, Kotest IntelliJ plugin will not invoke the test with Gradle, so the --add-opens is not applied.

— Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-intellij-plugin/issues/250#issuecomment-1518388871, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGWSTLVWXWC7K55IXJTXCMCHPANCNFSM6AAAAAAXALPV64 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

zakhenry commented 1 year ago

Ah yes this is a good solution thanks, doc ref for future reference: https://kotest.io/docs/intellij/intellij-properties.html

sgc109 commented 6 months ago

'withEnvironment' still doesn't work in kotest 5.5.5. I've opened the issue https://github.com/kotest/kotest/issues/4036

florianmutter commented 4 months ago

Could someone add an example what we need to put into kotest.properties to get withEnvironment {} working?