Chapter 1. Test your Red Hat build of Quarkus application with JUnit


After you compile your Quarkus Getting Started project, you can verify that it runs as expected by testing your application with the JUnit 6 framework.

Note

Alternatively, you can enable continuous testing of your Quarkus application. For more information, see Enabling and running continuous testing.

The Quarkus project generates the following two test dependencies in the pom.xml file:

  • quarkus-junit: Required for testing because it provides the @QuarkusTest annotation that controls the JUnit testing framework.
  • rest-assured: The rest-assured dependency is not required but, because it provides a convenient way to test HTTP endpoints, it is integrated. It automatically sets the correct URL, so no configuration is required.

Example pom.xml file:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-junit</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <scope>test</scope>
</dependency>

 

Note

These tests use the REST-Assured framework, but you can use a different library if you prefer.

Prerequisites

Procedure

  1. Open the generated pom.xml file and review the contents.

    The Maven Surefire plugin, maven-surefire-plugin, runs unit tests during the test phase of the build lifecycle when Quarkus enables the test profile. The plugin generates text and XML test reports.

    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
           <argLine>@{argLine}</argLine>
           <systemPropertyVariables>
             <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
             <maven.home>${maven.home}</maven.home>
           </systemPropertyVariables>
        </configuration>
    </plugin>

     

    Note the values of the following properties:

    • The java.util.logging.manager system property is set to ensure that your application uses the correct log manager for the test.
    • The maven.home property is automatically replaced by the location of the Maven home directory.
  2. Edit the src/test/java/org/acme/quickstart/GreetingResourceTest.java file to match the following content:

    package org.acme.quickstart;
    
    import io.quarkus.test.junit.QuarkusTest;
    import org.junit.jupiter.api.Test;
    
    import java.util.UUID;
    
    import static io.restassured.RestAssured.given;
    import static org.hamcrest.CoreMatchers.is;
    
    @QuarkusTest
    public class GreetingResourceTest {
    
        @Test
        public void testHelloEndpoint() {
            given()
              .when().get("/hello")
              .then()
                 .statusCode(200)
                 .body(is("Hello from Quarkus REST"));
        }
    
        @Test
        public void testGreetingEndpoint() {
            String uuid = UUID.randomUUID().toString();
            given()
              .pathParam("name", uuid)
              .when().get("/hello/greeting/{name}")
              .then()
                .statusCode(200)
                .body(is("hello " + uuid));
        }
    
    }

     

    Note

    By using the QuarkusTest runner, you instruct JUnit to start the application before starting the tests.

  3. Run the tests in one of the following ways:

    • Using Apache Maven:

      mvn test

       

    • Using Quarkus CLI:

      quarkus test

       

    • Using the Maven wrapper:

      ./mvnw test

       

      By default, tests run on port 8081 so they do not conflict with the running application. In Quarkus, the RestAssured dependency is configured to use this port.

      Note

      If you want to use a different client, use the @TestHTTPResource annotation to directly inject the URL of the tested application into a field in the Test class. This field can be of type String, URL, or URI. You can also enter the test path in the @TestHTTPResource annotation. For example, to test a resource exposed to /foo, add the following lines to your test:

      @TestHTTPResource("/foo")
      URL testUrl;
  4. If necessary, specify the test port in the quarkus.http.test-port configuration property.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top