이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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.

    Note

    Quarkus provides integration that automatically sets the correct URL, so no configuration is required.

Procedure

  1. Open the Getting Started project pom.xml file.
  2. 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>
  3. Verify that your pom.xml file includes the maven-surefire-plugin. Because this tutorial uses the JUnit 5 framework, the version of the maven-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>
  4. Set the java.util.logging.manager system property to use the correct log manager for test.
  5. 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));
        }
    
    }
  6. To run the test, enter the following command:

    ./mvnw clean verify

    You can also run the test directly from your IDE.

Note

This test uses HTTP to directly test the REST endpoint. When the test is triggered, the application will start before the test runs.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.