Skip to content

Commit

Permalink
Introduce @QuarkusIntegration test
Browse files Browse the repository at this point in the history
Resolves: #13818
  • Loading branch information
geoand committed Feb 15, 2021
1 parent f219b48 commit 76a7c2a
Show file tree
Hide file tree
Showing 29 changed files with 1,533 additions and 348 deletions.
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/building-native-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ duration can be changed using the `quarkus.test.native-image-wait-time` system p
to 300 seconds, use: `./mvnw verify -Pnative -Dquarkus.test.native-image-wait-time=300`.
====

[WARNING]
====
In the future, `@NativeImageTest` will be deprecated in favor of `@QuarkusIntegrationTest` which provides a superset of the testing
capabilities of `@NativeImageTest`. More information about `@QuarkusIntegrationTest` can be found in the link:getting-started-testing#quarkus-integration-test[Testing Guide].
====

By default, native tests runs using the `prod` profile.
This can be overridden using the `quarkus.test.native-image-profile` property.
For example, in your `application.properties` file, add: `quarkus.test.native-image-profile=test`.
Expand Down
17 changes: 17 additions & 0 deletions docs/src/main/asciidoc/getting-started-testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,23 @@ guide except injecting into tests (and the native executable runs in a separate

This is covered in the link:building-native-image[Native Executable Guide].

[WARNING]
====
Although `@NativeImageTest` is not yet deprecated, it will be in the future as it's functionality is covered by `@QuarkusIntegrationTest`
which is described in the following section.
====

[#quarkus-integration-test]
== Using @QuarkusIntegrationTest

`@QuarkusIntegrationTest` should be used to launch and test the artifact produced by the Quarkus build, and supports testing a jar (of whichever type), a native image or container-image.
Put simply, this means that if the result of a Quarkus build (`mvn package` or `gradle build`) is a jar, that jar will be launched as `java -jar ...` and tests run against it.
If instead a native image was build, then the application is launched as `./application ...` and again the tests run against the running application.
Finally, if a container image was created during the build (by using including the `quarkus-container-image-jib` or `quarkus-container-image-docker` extensions and having the
`quarkus.container-image.build=true` property configured), then a container is created and run (this requires the `docker` executable being present).

As is the case with `@NativeImageTest`, this is a black box test that supports the same set features and has the same limitations.

[[test-from-ide]]
== Running `@QuarkusTest` from an IDE

Expand Down
72 changes: 69 additions & 3 deletions integration-tests/container-image/quarkus-standard-way/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

<artifactId>quarkus-integration-test-container-image-standard</artifactId>
<name>Quarkus - Integration Tests - Container Image - Standard</name>
<description>Container Image integration tests that use @QuarkusProdModeTest</description>
<description>Container Image integration tests that use '@QuarkusProdModeTest' and '@QuarkusIntegrationTests'</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>

<!-- made test scope only to force Maven to build these dependencies before running the tests-->
Expand Down Expand Up @@ -70,7 +70,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -83,4 +83,70 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>test-quarkus-integration-test</id>
<activation>
<property>
<name>test-containers</name>
</property>
</activation>
<properties>
<quarkus.container-image.build>true</quarkus.container-image.build>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.container.image;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class GreetingResourceIT {

@Test
public void testHelloEndpoint() {
given()
.when().get("/greeting")
.then()
.statusCode(200)
.body(is("hello"));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.it.panache;

import io.quarkus.test.junit.NativeImageTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;

/**
* Test various Panache operations running in native mode
*/
@NativeImageTest
@QuarkusIntegrationTest
public class PanacheFunctionalityInGraalITCase extends PanacheFunctionalityTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import io.quarkus.hibernate.orm.runtime.PersistenceUnitUtil;
import io.quarkus.test.junit.DisabledOnIntegrationTest;
import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
Expand Down Expand Up @@ -135,7 +136,7 @@ public void jaxbDeserializationHasAllFields() throws JsonProcessingException, JA
/**
* This test is disabled in native mode as there is no interaction with the quarkus integration test endpoint.
*/
@DisabledOnNativeImage
@DisabledOnIntegrationTest
@Test
public void jsonbDeserializationHasAllFields() throws JsonProcessingException {
// set Up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.quarkus.it.panache.reactive;

import io.quarkus.test.junit.NativeImageTest;
import io.quarkus.test.junit.QuarkusIntegrationTest;

/**
* Test various Panache operations running in native mode
*/
@NativeImageTest
@QuarkusIntegrationTest
public class PanacheFunctionalityInGraalITCase extends PanacheFunctionalityTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.quarkus.maven.it;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import org.apache.maven.shared.invoker.MavenInvocationException;
import org.junit.jupiter.api.Test;

import io.quarkus.maven.it.verifier.MavenProcessInvocationResult;
import io.quarkus.maven.it.verifier.RunningInvoker;

// meant to test that @QuarkusIntegrationTest can properly launch jars
@DisableForNative
public class QuarkusIntegrationTestIT extends MojoTestBase {

@Test
public void testFastJar() throws MavenInvocationException, IOException {
doTest("qit-fast-jar", "-Dfastjar");
}

@Test
public void testLegacyJar() throws MavenInvocationException, IOException {
doTest("qit-legacy-jar", "-Dlegacyjar");
}

@Test
public void testUberJar() throws MavenInvocationException, IOException {
doTest("qit-uber-jar", "-Duberjar");
}

private void doTest(String projectName, String profile) throws MavenInvocationException, IOException {
File testDir = initProject("projects/reactive-routes", "projects/" + projectName);
RunningInvoker running = new RunningInvoker(testDir, false);

MavenProcessInvocationResult result = running
.execute(Arrays.asList("verify",
profile), Collections.emptyMap());

await().atMost(2, TimeUnit.MINUTES).until(() -> result.getProcess() != null && !result.getProcess().isAlive());
assertThat(running.log()).containsIgnoringCase("BUILD SUCCESS");
running.stop();
}
}
Loading

0 comments on commit 76a7c2a

Please sign in to comment.