我使用 gradle kotlin DSL,我需要在运行 build
或 test
时排除我的验收测试。目前我有
tasks.withType<Test> {
exclude("*acceptance*")
}
这是行不通的。执行验收测试,不排除。
我还需要配置我的 build.gradle.kts
来运行我的验收测试。目前我有一个 acceptance
目录,它位于 src/test/groovy
下,我根据文档 here 创建了一个 acceptanceTest 任务。 .此配置不运行验收测试。
sourceSets {
create("acceptance") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
val acceptanceImplementation by configurations.getting {
extendsFrom(configurations.implementation.get())
}
val acceptanceTest = task<Test>("acceptanceTest") {
description = "Runs Acceptance tests."
group = "verification"
testClassesDirs = sourceSets["test"].output.classesDirs
classpath = sourceSets["acceptance"].runtimeClasspath
shouldRunAfter("test")
}
tasks.check { dependsOn(acceptanceTest) }
最佳答案
exclude
模式使用 Ant 风格的路径匹配,因此,为了排除名为 acceptance
的目录中的所有测试,您需要执行以下操作:
exclude("**/acceptance/**")
但是,如您所示,对类型为 Test
的所有任务执行此操作永远不会运行验收测试。只有单元测试需要跳过它,这是名为 test
的任务。
要运行验收测试,您将使用与 acceptanceTest
任务中的 include
相同的路径模式。
关于gradle - Kotlin Gradle DSL 在运行单元测试时排除验收测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56634236/