How to have two sets of tests in JUnit Platform in Gradle

Viewed 1714

I'm using JUnit 5 platform via Gradle.

My current build file has configuration clause

junitPlatform {
    platformVersion '1.0.0-M5'
    logManager 'java.util.logging.LogManager'
    enableStandardTestTask true

    filters {
        tags {
            exclude 'integration-test'
        }
        packages {
            include 'com.scherule.calendaring'
        }
    }
}

That works fine. But I also need to run integration tests which require the application to be built, dockerized and run in background. So I should have second configuration like this which would be launched only then... how to achieve this? Normally I would extend Test task creating IntegrationTest task but it doesn't fit JUnit Platform where there is no simple task running tests...

I know I could do sth like this

task integrationTests(dependsOn: "startMyAppContainer") {
    doLast {
        def request = LauncherDiscoveryRequestBuilder.request()
                .selectors(selectPackage("com.scherule.calendaring"))
                .filters(includeClassNamePatterns(".*IntegrationTest"))
                .build()

        def launcher = LauncherFactory.create()

        def listener = new SummaryGeneratingListener()
        launcher.registerTestExecutionListeners(listener)
        launcher.execute(request)
    }

    finalizedBy(stopMyAppContainer)
}

but is there a simpler way? More consistent.

1 Answers
Related