Test your application

Red Hat build of Quarkus 3.33

Red Hat Customer Content Services

Abstract

This guide describes how to test your application.

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.

Chapter 2. Enable and run continuous testing

With Red Hat build of Quarkus, you can continuously test your code changes as you develop your applications. Quarkus provides a continuous testing feature, which you can run immediately after you make and save a change to the code.

When you run continuous testing, testing is paused after you start the application. You can resume the testing as soon as the application starts. The Quarkus application determines which tests run so that tests are run only on code that has changed.

The continuous testing feature of Quarkus is enabled by default. You can choose to disable continuous testing by setting the quarkus.test.continuous-testing property in the src/main/resources/application.properties file to disabled.

Note

If you disabled continuous testing previously and want to enable it again, you must restart your Quarkus application before you can start testing.

Prerequisites

Procedure

  1. Start your Quarkus application.

    • If you created your Getting Started project by using the This content is not included.code.quarkus.redhat.com application or the Quarkus CLI, the Maven wrapper is provided when you generate the project. Enter the following command from your project directory:

      ./mvnw quarkus:dev

       

    • If you created your Getting Started project by using Apache Maven, which is installed on your machine, you can also choose the following command:

      mvn quarkus:dev

       

    • If you are running continuous testing in dev mode and are using the Quarkus CLI, enter the following command:

      quarkus dev

       

  2. View details of the testing status in the generated output log.

    Note

    To view the output log, you might need to scroll to the bottom of the screen.

    • When continuous testing is enabled, the following message is displayed:

      Press [e] to edit command line args (currently ''), [r] to re-run, [o] Toggle test output, [:] for the terminal, [h] for more options>

       

    • When continuous testing is paused, the following message is displayed:

      Press [e] to edit command line args (currently ''), [r] to resume testing, [o] Toggle test output, [:] for the terminal, [h] for more options>

       

      Note

      By default, when continuous testing is enabled, testing is paused after you start the application. To view the keyboard commands that are available for controlling how you run your tests, see Commands for controlling continuous testing.

  3. To start running the tests, press r on your keyboard.
  4. View the updated output log to monitor the test status and test results, check test statistics, and get guidance for follow-up actions. For example:

    All 2 tests are passing (0 skipped), 2 tests were run in 2094ms. Tests completed at 14:45:11.
    Press [e] to edit command line args (currently ''), [r] to re-run, [o] Toggle test output, [:] for the terminal, [h] for more options>

     

Verification

  1. Make a code change. For example, in a text editor, open the src/main/java/org/acme/quickstart/GreetingsResource.java file.
  2. Change the "hello" endpoint to return "Hello world" and save the file.

    import jakarta.ws.rs.GET;
    import jakarta.ws.rs.Path;
    import jakarta.ws.rs.Produces;
    import jakarta.ws.rs.core.MediaType;
    
    @Path("/hello")
    public class GreetingResource {
    
        @GET
        @Produces(MediaType.TEXT_PLAIN)
        public String hello() {
            return "Hello world";
        }
    }

     

  3. Verify that Quarkus immediately re-runs the test to test the changed code.
  4. View the output log to check the test results. In this example, the test checks whether the changed string contains the value "Hello from Quarkus REST". The test fails because the string was changed to "Hello world".

    2025-09-26 11:05:45,911 ERROR [io.qua.test] (Test runner thread) Test GreetingResourceTest#testHelloEndpoint() failed: java.lang.AssertionError: 1 expectation failed.
    Response body doesn't match expectation.
    Expected: is "Hello from Quarkus REST"
      Actual: Hello world
            at io.restassured.internal.ValidatableResponseOptionsImpl.body(ValidatableResponseOptionsImpl.java:238)
            at org.acme.quickstart.GreetingResourceTest.testHelloEndpoint(GreetingResourceTest.java:20)
    --
    1 test failed (1 passing, 0 skipped), 2 tests were run in 2076ms. Tests completed at 15:03:45.
    Press [e] to edit command line args (currently ''), [r] to re-run, [o] Toggle test output, [:] for the terminal, [h] for more options>

     

  5. To exit continuous testing, press Ctrl-C or q on your keyboard.
Note

If you change the value back to "Hello from Quarkus REST" again, the test automatically runs again.

2.1. Continuous testing commands

You can use hotkey commands on your keyboard to control your options for continuous testing. To view the full list of commands, press 'h' on your keyboard. The following options are available:

CommandDescription

r

Re-run all tests.

f

Re-run all tests that failed.

b

Toggle 'broken only' mode. Only the tests that were failing previously are run, even if other tests are affected by your code changes. This option might be useful if you change code that is used by many tests, but you want to only review the failed tests.

v

Print output detailing test failures from the last test run to the console. This option might be useful if there was a considerable amount of console output since the last test run.

p

Pause running tests temporarily. This might be useful if you are making many code changes, but do not want to get test feedback until you finish making the changes.

q

Exit continuous testing.

o

Print test output to the console. This is disabled by default. When test output is disabled, the output is filtered and saved, but not displayed on the console. You can view the test output on the Dev UI.

i

Toggle instrumentation-based reload. Using this option does not directly affect testing, but does allow live reload to occur. This might be useful to avoid a restart if a change does not affect the structure of a class.

l

Toggle live reload. Using this option does not directly affect testing, however, you can turn live reloading on and off.

s

Force restart. Using this option, you can force a scan of changed files and a live reload that includes the changes. Note that even if there are no code changes and live reload is disabled, the application still restarts.

Legal Notice

Copyright © Red Hat.
Except as otherwise noted below, the text of and illustrations in this documentation are licensed by Red Hat under the Creative Commons Attribution–Share Alike 3.0 Unported license . If you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, the Red Hat logo, JBoss, Hibernate, and RHCE are trademarks or registered trademarks of Red Hat, LLC. or its subsidiaries in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS is a trademark or registered trademark of Hewlett Packard Enterprise Development LP or its subsidiaries in the United States and other countries.
The OpenStack® Word Mark and OpenStack logo are trademarks or registered trademarks of the Linux Foundation, used under license.
All other trademarks are the property of their respective owners.