此内容没有您所选择的语言版本。
Chapter 4. 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.xmlfile and verify that thenativeprofile contains the following elements:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
failsafe-maven-pluginruns integration test and indicates the location of the produced native executable.Open the
src/test/java/org/acme/quickstart/NativeGreetingResourceIT.javafile and verify that it includes the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the test:
./mvnw verify -Pnative
./mvnw verify -PnativeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following example shows the output of this command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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-timesystem 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>
./mvnw verify -Pnative -Dquarkus.test.native-image-wait-time=<duration>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.1. Excluding tests when running as a native executable 复制链接链接已复制到粘贴板!
When you run tests against your native application, you can only interact with its HTTP endpoints. Tests do not run natively, therefore they cannot link against your application’s code like they can when running on the JVM.
You can share your test class between JVM and native executions and exclude certain tests with the @DisabledOnNativeImage annotation to run them only on the JVM.
4.2. Testing an existing native executable 复制链接链接已复制到粘贴板!
You can test against the existing executable build. This allows you to run multiple sets of tests in stages on the binary after it has been build.
Procedure
Run a test against an already built native executable:
./mvnw test-compile failsafe:integration-test
./mvnw test-compile failsafe:integration-testCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command runs the test against the existing native image using Failsafe Maven Plugin.
Alternatively, you can specify the path to the native executable with the following command where
<path>is the native image path:./mvnw test-compile failsafe:integration-test -Dnative.image.path=<path>
./mvnw test-compile failsafe:integration-test -Dnative.image.path=<path>Copy to Clipboard Copied! Toggle word wrap Toggle overflow