Separate integration and unit tests with Gradle.

huangapple go评论67阅读模式
英文:

Separate integration and unit tests with Gradle

问题

我正在迁移一个现有的Maven和JUnit 5项目,其中集成测试和单元测试分为不同的阶段:

  • *Test.java 单元测试在 test 阶段运行
  • *IT.java 集成测试在 verify 阶段运行

我该如何使用Gradle实现相同的分离?我理解Gradle的 check 任务相当于Maven的 verify

英文:

I'm migrating an existing Maven and JUnit 5 project where the integration and unit tests are separated into different phases:

  • the *Test.java unit tests are run on the test phase
  • the *IT.java integration tests are run on the verify phase

How do I accomplish the same separation with Gradle? It is my understanding that Gradle's check task is the equivalent to Maven's verify.

答案1

得分: 1

I ended up using filters to separate the unit and integration tests and to bind the integration tests to the check task:

tasks.named('test') {
    useJUnitPlatform {
        filter {
            includeTestsMatching "*Test"
            excludeTestsMatching "*IT"
        }
    }
}

def integrationTest = tasks.register("integrationTest", Test) {
    useJUnitPlatform {
        filter {
            includeTestsMatching '*IT'
            includeTestsMatching 'IT*'
            includeTestsMatching '*ITCase'
        }
    }
}

tasks.named('check') {
    dependsOn integrationTest
}
英文:

I ended up using filters to separate the unit and integration tests and to bind the integration tests to the check task:

tasks.named('test') {
    useJUnitPlatform {
        filter {
            includeTestsMatching "*Test"
            excludeTestsMatching "*IT"
        }
    }
}

def integrationTest = tasks.register("integrationTest", Test) {
    useJUnitPlatform {
        filter {
            includeTestsMatching '*IT'
            includeTestsMatching 'IT*'
            includeTestsMatching '*ITCase'
        }
    }
}

tasks.named('check') {
    dependsOn integrationTest
}

huangapple
  • 本文由 发表于 2023年4月10日 22:53:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75978156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定