gradle - Kotlin Gradle DSL 在运行单元测试时排除验收测试

标签 gradle build.gradle gradle-kotlin-dsl

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

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/

相关文章:

gradle - 如何在 Gradle Kotlin 构建中配置 processResources 任务

Android studio 导入 gradle 问题

intellij-idea - "Re-run SpringBoot Configuration Annotation Processor"在 Groovy、IntelliJ 和 Gradle 项目中

c++ - 构建 C/C++ 代码时的 Gradle 编译器输出

android - 所有 com.android.support 库必须使用完全相同的版本规范

kotlin - 使用kotlin和kapt读取注释处理器中的资源

android - Android Studio Gradle Build Error无法合并dex

android - 无法解决 : com. github.barteksc :android-pdf-viewer:3. 2.0-beta.1 如何解决此问题

android - java.lang.IllegalAccessError : Method 'void android. support.v4.content

android 按口味链不同的 applicationId 和 applicationIdSuffix