1.13. ネイティブ実行可能ファイルをテストする
ネイティブ実行可能ファイルの機能をテストするには、ネイティブモードでアプリケーションをテストします。@QuarkusIntegrationTest アノテーションを使用してネイティブ実行可能ファイルをビルドし、HTTP エンドポイントに対してテストを実行します。
次の例は、GraalVM または Mandrel のローカルインストールを使用してネイティブ実行可能ファイルをテストする方法を示しています。テストを実行する前に、次の点を考慮してください。
- ネイティブ実行可能ファイルの作成 で説明されているように、Red Hat build of Quarkus はこのシナリオをサポートしていません。
- ここでテストするネイティブ実行可能ファイルは、ホストのオペレーティングシステムとアーキテクチャーに一致する必要があります。したがって、ネイティブバイナリーが macOS 上のコンテナー内にビルドされている場合、この手順は使用できません。
手順
pom.xmlファイルを開き、buildセクションに次の要素が含まれていることを確認します。<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>${surefire-plugin.version}</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> <configuration> <systemPropertyVariables> <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <maven.home>${maven.home}</maven.home> </systemPropertyVariables> </configuration> </execution> </executions> </plugin>-
Maven Failsafe プラグイン (
maven-failsafe-plugin) は結合テストを実行し、生成されたネイティブ実行可能ファイルの場所を示します。
-
Maven Failsafe プラグイン (
src/test/java/org/acme/GreetingResourceIT.javaファイルを開き、次のコンテンツが含まれていることを確認します。package org.acme; import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest1 public class GreetingResourceIT extends GreetingResourceTest {2 // Execute the same tests but in native mode. }
テストを実行します。
./mvnw verify -Dnative以下の例は、このコマンドの出力を示しています。
./mvnw verify -Dnative .... GraalVM Native Image: Generating 'getting-started-1.0.0-SNAPSHOT-runner' (executable)... ======================================================================================================================== [1/8] Initializing... (6.6s @ 0.22GB) Java version: 21.0.4+7-LTS, vendor version: Mandrel-23.1.4.0-1b1 Graal compiler: optimization level: 2, target machine: x86-64-v3 C compiler: gcc (redhat, x86_64, 13.2.1) Garbage collector: Serial GC (max heap size: 80% of RAM) 2 user-specific feature(s) - io.quarkus.runner.Feature: Auto-generated class by Red Hat build of Quarkus from the existing extensions - io.quarkus.runtime.graal.DisableLoggingFeature: Disables INFO logging during the analysis phase [2/8] Performing analysis... [******] (40.0s @ 2.05GB) 10,318 (86.40%) of 11,942 types reachable 15,064 (57.36%) of 26,260 fields reachable 52,128 (55.75%) of 93,501 methods reachable 3,298 types, 109 fields, and 2,698 methods registered for reflection 63 types, 68 fields, and 55 methods registered for JNI access 4 native libraries: dl, pthread, rt, z [3/8] Building universe... (5.9s @ 1.31GB) [4/8] Parsing methods... [**] (3.7s @ 2.08GB) [5/8] Inlining methods... [***] (2.0s @ 1.92GB) [6/8] Compiling methods... [******] (34.4s @ 3.25GB) [7/8] Layouting methods... [**] (4.1s @ 1.78GB) [8/8] Creating image... [**] (4.5s @ 2.31GB) 20.93MB (48.43%) for code area: 33,233 compilation units 21.95MB (50.80%) for image heap: 285,664 objects and 8 resources 337.06kB ( 0.76%) for other data 43.20MB in total .... [INFO] [INFO] --- maven-failsafe-plugin:3.0.0-M7:integration-test (default) @ getting-started --- [INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running org.acme.GreetingResourceIT __ ____ __ _____ ___ __ ____ ______ --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ --\___\_\____/_/ |_/_/|_/_/|_|\____/___/ 2024-09-27 14:04:52,681 INFO [io.quarkus] (main) getting-started 1.0.0-SNAPSHOT native (powered by Quarkus 3.15.7.redhat-00001) started in 0.038s. Listening on: http://0.0.0.0:8081 2024-09-27 14:04:52,682 INFO [io.quarkus] (main) Profile prod activated. 2024-09-27 14:04:52,682 INFO [io.quarkus] (main) Installed features: [cdi, rest, smallrye-context-propagation, vertx] [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.696 s - in org.acme.GreetingResourceIT [INFO] [INFO] Results: [INFO] [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-failsafe-plugin:3.0.0-M7:verify (default) @ getting-started ---注記Quarkus は、ネイティブイメージが起動するのを 60 秒間待機してから、自動的にネイティブテストに失敗します。この期間は、
quarkus.test.wait-timeシステムプロパティーを設定することで変更できます。以下のコマンドを使用して、待機時間を延長できます。この場合の
<duration>は待機時間 (秒単位) です。./mvnw verify -Dnative -Dquarkus.test.wait-time=<duration>注記-
デフォルトでは、
quarkus.test.native-image-profileプロパティーで変更されていない限り、ネイティブテストはprodプロファイルを使用して実行されます。
-
デフォルトでは、