Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce @QuarkusIntegration test
Browse files Browse the repository at this point in the history
Resolves: #13818
geoand committed Feb 16, 2021
1 parent 9b63b6b commit ba08625
Showing 31 changed files with 1,548 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
@@ -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`.
17 changes: 17 additions & 0 deletions docs/src/main/asciidoc/getting-started-testing.adoc
Original file line number Diff line number Diff line change
@@ -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

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
@@ -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-->
@@ -40,6 +40,16 @@
<artifactId>assertj-core</artifactId>
<scope>test</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>

<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
@@ -70,7 +80,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>
@@ -83,4 +93,60 @@
</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>
</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
@@ -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;
@@ -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
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,15 @@
package io.quarkus.maven.it;

import java.io.IOException;

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

@DisableForNative
public class FastJarQuarkusIntegrationTestIT extends QuarkusITBase {

@Test
public void testFastJar() throws MavenInvocationException, IOException {
doTest("qit-fast-jar", "fastjar");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.maven.it;

import java.io.IOException;

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

@DisableForNative
public class LegacyJarQuarkusIntegrationTestIT extends QuarkusITBase {

@Test
public void testFastJar() throws MavenInvocationException, IOException {
doTest("qit-legacy-jar", "legacyjar");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 io.quarkus.maven.it.verifier.MavenProcessInvocationResult;
import io.quarkus.maven.it.verifier.RunningInvoker;

// meant to test that @QuarkusIntegrationTest can properly launch jars
abstract class QuarkusITBase extends MojoTestBase {

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

MavenProcessInvocationResult packageInvocationResult = packageInvocation
.execute(Arrays.asList("package", "-B",
"-D" + profile), Collections.emptyMap());

await().atMost(1, TimeUnit.MINUTES)
.until(() -> packageInvocationResult.getProcess() != null && !packageInvocationResult.getProcess().isAlive());
assertThat(packageInvocation.log()).containsIgnoringCase("BUILD SUCCESS");

RunningInvoker integrationTestsInvocation = new RunningInvoker(testDir, false);

MavenProcessInvocationResult integrationTestsInvocationResult = integrationTestsInvocation
.execute(Arrays.asList("failsafe:integration-test", "-B",
"-D" + profile), Collections.emptyMap());

await().atMost(1, TimeUnit.MINUTES)
.until(() -> integrationTestsInvocationResult.getProcess() != null
&& !integrationTestsInvocationResult.getProcess().isAlive());
assertThat(integrationTestsInvocation.log()).containsIgnoringCase("BUILD SUCCESS");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.maven.it;

import java.io.IOException;

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

@DisableForNative
public class UberJarQuarkusIntegrationTestIT extends QuarkusITBase {

@Test
public void testFastJar() throws MavenInvocationException, IOException {
doTest("qit-uber-jar", "uberjar");
}
}
Loading

0 comments on commit ba08625

Please sign in to comment.