Skip to content

Commit

Permalink
Coverage for mixing @QuarkusMainTest and @QuarkusTest in the same pac…
Browse files Browse the repository at this point in the history
…kage

Required for https://issues.redhat.com/browse/QUARKUS-2789
Names of the tests are important, see the first comment to the issue
  • Loading branch information
fedinskiy committed Jan 6, 2023
1 parent ba3614d commit 2819794
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lifecycle-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</activation>
<properties>
<!-- please keep Mandrel and RHBQ version compatible -->
<quarkus.platform.version>2.13.4.Final</quarkus.platform.version>
<quarkus.platform.version>2.13.6.Final</quarkus.platform.version>
</properties>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ private Main() {

public static void main(String... args) {
LOG.info(ARGUMENTS_FROM_MAIN + String.join(",", args));
Quarkus.run(args);
if (args.length > 0 && "cli".equals(args[0])) {
return;
} else {
Quarkus.run(args);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.ts.lifecycle;

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

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class AlphabeticallyFirstTest {

@Test
public void shouldBeOk() {
given()
.when().get("/args")
.then()
.statusCode(200)
.body(is(""));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.ts.lifecycle;

import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.main.Launch;
import io.quarkus.test.junit.main.LaunchResult;
import io.quarkus.test.junit.main.QuarkusMainTest;

@QuarkusMainTest
public class HelloMainTest {

@Test
@Launch({ "cli", "Hello", "World" })
public void annotatedLaunch(LaunchResult result) {
List<String> outputStream = result.getOutputStream();
String args = null;
for (String output : outputStream) {
if (output.contains("Received arguments:")) {
args = output;
}
}
Assertions.assertNotNull(args);
Assertions.assertTrue(args.contains("Hello"), "No 'Hello' in the output!");
Assertions.assertTrue(args.contains("World"), "No 'World' in the output!");
}
}

0 comments on commit 2819794

Please sign in to comment.