'How to run @QuarkusIntegrationTest in a Gradle project?

I want to run a Quarkus integration test in order to verify OpenAPI yaml generated from the source code. According to the documentation, it should be possible to do it using the @QuarkusIntegrationTest annotation. However the it is not explained how to mek it work.

As a test annotated with @QuarkusIntegrationTest tests the result of the build, it should be run as part of the integration test suite - i.e. via the maven-failsafe-plugin if using Maven or an additional task if using Gradle.

Unfortunately, it is not clear what this means and how to configure that "additional task" in Gradle.

Question: How to run a Quarkus Integration Test in a Gradle project?



Solution 1:[1]

Running integration test will require the final artifact to be built.

Thus before running the test task, you will need to run a quarkusBuild. Once your app is build, and if your tests are in src/test/java you can simply run gradle test to run them.

In order to make sure your artifact is always available before you run your integration tests, you can create a new task of type test, that will depend on quarkusBuild, that would only run those tests. For example :

task integrationTest(type: Test) {
    description = "Runs integration tests"
    group = "verification"
    useJUnitPlatform()

    // Include only integration test package
    include 'io/quarkus/gradle/integrationtest/*.class'
}

integrationTest.dependsOn(quarkusBuild)

or you can create a custom source set and put your test there, this is documented here: https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests

Solution 2:[2]

If your build.gradle file contains

plugins {
    id 'io.quarkus'
}

then you should be able to run the @QuarkusIntegrationTest tests with

.\gradlew quarkusIntTest

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guillaume le Floch
Solution 2 tbsalling