当我在 Gradle 中运行测试时,我想传递一些属性:
./gradlew test -DmyProperty=someValue
所以在我的 Spock 测试中,我将使用检索值:
def value = System.getProperty("myProperty")
我正在使用 kotlin gradle dsl。当我尝试使用本文档中的“tasks.test”时: https://docs.gradle.org/current/userguide/java_testing.html#test_filtering
'test' 在我的 build.gradle.kts
文件中无法识别。
我假设我需要使用类似于下面帖子中的答案的东西,但不清楚在使用 gradle kotlin DSL 时应该如何完成。
最佳答案
您的链接问题的答案可以 1:1 翻译成 kotlin DSL。这是使用 junit5 的完整示例。
dependencies {
// ...
testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")
testImplementation(kotlin("test-junit5"))
}
tasks.withType<Test> {
useJUnitPlatform()
// Project property style - optional property.
// ./gradlew test -Pcassandra.ip=xx.xx.xx.xx
systemProperty("cassandra.ip", project.properties["cassandra.ip"])
// Project property style - enforced property.
// The build will fail if the project property is not defined.
// ./gradlew test -Pcassandra.ip=xx.xx.xx.xx
systemProperty("cassandra.ip", project.property("cassandra.ip"))
// system property style
// ./gradlew test -Dcassandra.ip=xx.xx.xx.xx
systemProperty("cassandra.ip", System.getProperty("cassandra.ip"))
}
关于java - 如何通过 Kotlin Gradle 和 -D 为我的测试提供系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56628983/