将验收测试作为单独的 Gradle 任务运行



我正在尝试为我的项目配置Gradle with Kotlin DSL。它由两个模块组成。模块 A 是一个简单的Java 11应用程序。模块 B 使用 Spek 保留以 Kotlin 编写的验收测试。

我想配置 gradle,以便gradle test不运行验收测试,并且这些测试仅与任务 gradle acceptanceTest 一起运行。我尝试了下面的配置,其中包含和排除的其他过滤器变体,但没有运气。我错过了什么?

tasks.withType<Test> {
    println("always printed: configuration phase test")
    useJUnitPlatform()
    filter {
        exclude("acceptance.*")
    }
    doLast {
        println("only printed if executed: execution phase test")
    }
}
val acceptanceTest: Task by tasks.creating(Test::class) {
    println("always printed: configuration phase ac")
    useJUnitPlatform {
        includeEngines("spek2")
    }
    filter {
        include("acceptance.*")
    }
    doLast {
        println("only printed if executed: execution phase ac")
    }
}

过滤器是不必要的。我只是在错误的地方acceptanceTest任务...移动到acceptance模块后,它按预期工作。

最新更新