Test your application
Abstract
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.
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@QuarkusTestannotation that controls the JUnit testing framework. -
rest-assured: Therest-assureddependency 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>
These tests use the REST-Assured framework, but you can use a different library if you prefer.
Prerequisites
- You have compiled the Quarkus Getting Started project. For more information, see Build your first Quarkus application.
Procedure
Open the generated
pom.xmlfile and review the contents.The Maven Surefire plugin,
maven-surefire-plugin, runs unit tests during thetestphase of the build lifecycle when Quarkus enables thetestprofile. 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.managersystem property is set to ensure that your application uses the correct log manager for the test. -
The
maven.homeproperty is automatically replaced by the location of the Maven home directory.
-
The
Edit the
src/test/java/org/acme/quickstart/GreetingResourceTest.javafile 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)); } }NoteBy using the
QuarkusTestrunner, you instruct JUnit to start the application before starting the tests.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
8081so they do not conflict with the running application. In Quarkus, theRestAssureddependency is configured to use this port.NoteIf you want to use a different client, use the
@TestHTTPResourceannotation to directly inject the URL of the tested application into a field in theTestclass. This field can be of typeString,URL, orURI. You can also enter the test path in the@TestHTTPResourceannotation. For example, to test a resource exposed to/foo, add the following lines to your test:@TestHTTPResource("/foo") URL testUrl;
-
If necessary, specify the test port in the
quarkus.http.test-portconfiguration 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.
If you disabled continuous testing previously and want to enable it again, you must restart your Quarkus application before you can start testing.
Prerequisites
- You have compiled the Quarkus Getting Started application (or any other application). For more information, see Compile and start the Quarkus Getting Started project.
Procedure
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
View details of the testing status in the generated output log.
NoteTo 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>
NoteBy 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.
-
To start running the tests, press
ron your keyboard. 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
-
Make a code change. For example, in a text editor, open the
src/main/java/org/acme/quickstart/GreetingsResource.javafile. 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"; } }- Verify that Quarkus immediately re-runs the test to test the changed code.
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>-
To exit continuous testing, press
Ctrl-Corqon your keyboard.
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:
| Command | Description |
|---|---|
| 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. |