我使用 gradle kotlin DSL,我需要在运行build
或test
时排除我的验收测试。目前我有
tasks.withType<Test> {
exclude("*acceptance*")
}
这行不通。执行验收测试,不排除。
我还需要配置我的build.gradle.kts
以运行验收测试。目前我有一个acceptance
目录,该目录位于src/test/groovy
下,并且我已经根据此处的文档创建了一个验收测试任务。验收测试不使用此配置运行。
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
使用相同的路径模式。