建.Kotlin Gradle DSL 用于在运行单元测试时排除验收测试



我使用 gradle kotlin DSL,我需要在运行buildtest时排除我的验收测试。目前我有

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使用相同的路径模式。

最新更新