英文:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论