https://kotlinlang.org logo
#kotest
Title
# kotest
p

Pitel

03/15/2022, 9:26 AM
Any idea how to pass gradle parameters to tests?
Copy code
./gradlew -DproxySet=true -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8080 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8080 -Pasdfproxy=asdf :phoenix:testDebugUnitTest --tests PropTest
Copy code
class PropTest: StringSpec({
    "props" {
        System.getProperties().keys
            .filterIsInstance<String>()
            .filter { it.contains("proxy", true) }
            .also { println(it) }
            .shouldNotBeEmpty()
    }
})
And this test is failing.
b

Big Chungus

03/15/2022, 9:41 AM
You need to explicitly pass them to Test task sytem properties, because test task runs on forked JVM instance and not the one gradle itself is using.
Copy code
tasks {
  test {
    System.getProperties().forEach { (k,v) -> systemProperty(k, v)
    }
  }
}
🎉 1
👍🏻 1
Do note that it will not pass in
-Pasdfproxy=asdf
, because it's a gradle property and not sys property (-P vs -D)
c

christophsturm

03/15/2022, 10:00 AM
or use env variables instead of properties
b

Big Chungus

03/15/2022, 10:00 AM
I don't think env variables are passed in to test fork either
c

christophsturm

03/15/2022, 10:01 AM
I use them for that all the time so i think they are.
👍 2
2 Views