Skip to content

Commit

Permalink
Merge pull request #21185 from geoand/#21131
Browse files Browse the repository at this point in the history
Introduce the ability to run @QuarkusIntegrationTests against remote apps
  • Loading branch information
geoand authored Nov 8, 2021
2 parents 0d95838 + af978bc commit fa55de3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
18 changes: 18 additions & 0 deletions docs/src/main/asciidoc/getting-started-testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,24 @@ As a test annotated with `@QuarkusIntegrationTest` tests the result of the build
These tests will **not** work if run in the same phase as `@QuarkusTest` as Quarkus has not yet created the final artifact.
====

=== Executing against a running application

[WARNING]
====
This feature is considered experimental and is likely to change in future versions of Quarkus.
====

`@QuarkusIntegrationTest` supports executing tests against an already running instance of the application. This can be achieved by setting the
`quarkus.http.test-host` system property when running the tests.

An example use of this could be the following Maven command, that forces `@QuarkusIntegrationTest` to execute against that is accessible at `http://1.2.3.4:4321`:

[source,bash]
----
./mvnw verify -Dquarkus.http.test-host=1.2.3.4 -Dquarkus.http.test-port=4321
----


== Mixing `@QuarkusTest` with other type of tests

Mixing tests annotated with `@QuarkusTest` with tests annotated with either `@QuarkusDevModeTest`, `@QuarkusProdModeTest` or `@QuarkusUnitTest`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.quarkus.test.common;

import java.io.IOException;
import java.util.Map;

/**
* A launcher that simply sets the {@code quarkus.http.host} property based on the value {@code quarkus.http.test-host}
* in order to support the case of running integration tests against an already running application
* using RestAssured without any chances.
*
* This is highly experimental, so changes are to be expected.
*/
@SuppressWarnings("rawtypes")
public class TestHostLauncher implements ArtifactLauncher {

private String previousHost;

@Override
public void start() throws IOException {
// set 'quarkus.http.host' to ensure that RestAssured targets the proper host
previousHost = System.setProperty("quarkus.http.host", System.getProperty("quarkus.http.test-host"));
}

@Override
public void close() throws IOException {
if (previousHost != null) {
System.setProperty("quarkus.http.host", previousHost);
}
}

@Override
public boolean listensOnSsl() {
return false;
}

@Override
public void includeAsSysProps(Map systemProps) {

}

@Override
public void init(InitContext initContext) {
throw new IllegalStateException("Should not be called");
}

@Override
public LaunchResult runToCompletion(String[] args) {
throw new IllegalStateException("Should not be called");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.quarkus.test.common.ArtifactLauncher;
import io.quarkus.test.common.DevServicesContext;
import io.quarkus.test.common.RestAssuredURLManager;
import io.quarkus.test.common.TestHostLauncher;
import io.quarkus.test.common.TestResourceManager;
import io.quarkus.test.common.TestScopeManager;
import io.quarkus.test.junit.launcher.ArtifactLauncherProvider;
Expand Down Expand Up @@ -171,13 +172,18 @@ public void close() throws Throwable {
additionalProperties.putAll(resourceManagerProps);

ArtifactLauncher<?> launcher = null;
ServiceLoader<ArtifactLauncherProvider> loader = ServiceLoader.load(ArtifactLauncherProvider.class);
for (ArtifactLauncherProvider launcherProvider : loader) {
if (launcherProvider.supportsArtifactType(artifactType)) {
launcher = launcherProvider.create(
new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context, requiredTestClass,
devServicesLaunchResult));
break;
String testHost = System.getProperty("quarkus.http.test-host");
if ((testHost != null) && !testHost.isEmpty()) {
launcher = new TestHostLauncher();
} else {
ServiceLoader<ArtifactLauncherProvider> loader = ServiceLoader.load(ArtifactLauncherProvider.class);
for (ArtifactLauncherProvider launcherProvider : loader) {
if (launcherProvider.supportsArtifactType(artifactType)) {
launcher = launcherProvider.create(
new DefaultArtifactLauncherCreateContext(quarkusArtifactProperties, context, requiredTestClass,
devServicesLaunchResult));
break;
}
}
}
if (launcher == null) {
Expand Down

0 comments on commit fa55de3

Please sign in to comment.