이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 1. Verify test dependencies
For this tutorial, you must have a completed Quarkus Getting Started project and the project pom.xml
file must include the quarkus-junit5
and rest-assured
dependencies. These dependencies will be present if you completed the Quarkus Getting Started exercise or if you downloaded the completed example.
-
The
quarkus-junit5
dependency is required for testing because it provides the@QuarkusTest
annotation that controls the testing framework. The
rest-assured
dependency is not required but you can use it as a convenient way to test HTTP endpoints.NoteQuarkus provides integration that automatically sets the correct URL, so no configuration is required.
Procedure
-
Open the Getting Started project
pom.xml
file. Verify that the following dependencies are in the file and add them if necessary:
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-junit5</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <scope>test</scope> </dependency>
Verify that your
pom.xml
file includes themaven-surefire-plugin
. Because this tutorial uses the JUnit 5 framework, the version of themaven-surefire-plugin
must be set because the default version does not support Junit 5:<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>${surefire-plugin.version}</version> <configuration> <systemProperties> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> </systemProperties> </configuration> </plugin>
-
Set the
java.util.logging.manager
system property to use the correct log manager for test. Verify that the
GreetingResourceTest.java
file contains the following content and add it if necessary: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")); } @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)); } }
To run the test, enter the following command:
./mvnw clean verify
You can also run the test directly from your IDE.
This test uses HTTP to directly test the REST endpoint. When the test is triggered, the application will start before the test runs.