Chapter 13. Testing the native executable
Test the application running in the native mode to test the functionality of the native executable. Use @NativeImageTest
annotation to build the native executable and run test against the http endpoints.
Procedure
Open the
pom.xml
file and verify that thenative
profile contains the following elements:<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>
The
failsafe-maven-plugin
runs integration test and indicates the location of the produced native executable.Open the
src/test/java/org/acme/quickstart/NativeGreetingResourceIT.java
file and verify that it includes the following content:package org.acme.quickstart; import io.quarkus.test.junit.NativeImageTest; @NativeImageTest 1 public class NativeGreetingResourceIT extends GreetingResourceTest { 2 // Run the same tests }
Run the test:
./mvnw verify -Pnative
The following example shows the output of this command:
./mvnw verify -Pnative ... [getting-started-1.0-SNAPSHOT-runner:18820] universe: 587.26 ms [getting-started-1.0-SNAPSHOT-runner:18820] (parse): 2,247.59 ms [getting-started-1.0-SNAPSHOT-runner:18820] (inline): 1,985.70 ms [getting-started-1.0-SNAPSHOT-runner:18820] (compile): 14,922.77 ms [getting-started-1.0-SNAPSHOT-runner:18820] compile: 20,361.28 ms [getting-started-1.0-SNAPSHOT-runner:18820] image: 2,228.30 ms [getting-started-1.0-SNAPSHOT-runner:18820] write: 364.35 ms [getting-started-1.0-SNAPSHOT-runner:18820] [total]: 52,777.76 ms [INFO] [INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ getting-started --- [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running org.acme.quickstart.NativeGreetingResourceIT Executing [/data/home/gsmet/git/quarkus-quickstarts/getting-started/target/getting-started-1.0-SNAPSHOT-runner, -Dquarkus.http.port=8081, -Dtest.url=http://localhost:8081, -Dquarkus.log.file.path=build/quarkus.log] 2019-04-15 11:33:20,348 INFO [io.quarkus] (main) Quarkus 999-SNAPSHOT started in 0.002s. Listening on: http://[::]:8081 2019-04-15 11:33:20,348 INFO [io.quarkus] (main) Installed features: [cdi, resteasy] [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.387 s - in org.acme.quickstart.NativeGreetingResourceIT ...
NoteQuarkus waits for 60 seconds for the native image to start before automatically failing the native tests. You can change this duration using the
quarkus.test.native-image-wait-time
system property.You can extend the wait time using the following command where
<duration>
is the wait time in seconds:./mvnw verify -Pnative -Dquarkus.test.native-image-wait-time=
<duration>