1

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.

Fábio
  • 3,291
  • 5
  • 36
  • 49
  • 1
    For a reputable answer, i would cite *all of* https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests – xerx593 Apr 10 '23 at 15:00
  • 2
    It's possible to filter the included tests in Gradle https://stackoverflow.com/a/31468902/4161471. However, it would be more idiomatic to move the different types of tests into different source sets. The [JVM Test Suite](https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html) plugin is the best way to achieve this. – aSemy Apr 10 '23 at 21:18

1 Answers1

0

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
}
Fábio
  • 3,291
  • 5
  • 36
  • 49