Skip to content

Commit

Permalink
Allow mixing @QuarkusTest and @QuarkusMainTest
Browse files Browse the repository at this point in the history
This is done by "restarting" the application when one
test type follows the other.

Fixes: #28486
  • Loading branch information
geoand committed Oct 11, 2022
1 parent 14ab95c commit f997c67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,26 @@ private void ensurePrepared(ExtensionContext extensionContext, Class<? extends Q
throws Exception {
JBossVersion.disableVersionLogging();

boolean mixedWithQuarkusTest = false;
ExtensionContext.Store store = extensionContext.getStore(ExtensionContext.Namespace.GLOBAL);
Class<?> testType = store.get(IO_QUARKUS_TESTING_TYPE, Class.class);
if (testType != null) {
if (testType != QuarkusMainTest.class) {
throw new IllegalStateException(
"Cannot mix both @QuarkusMainTest based tests and " + testType.getName()
+ " based tests in the same run");
if (testType.equals(QuarkusTest.class)) {
mixedWithQuarkusTest = true;
} else {
throw new IllegalStateException(
"Cannot mix both @QuarkusMainTest based tests and " + testType.getName()
+ " based tests in the same run");
}
}
} else {
store.put(IO_QUARKUS_TESTING_TYPE, QuarkusMainTest.class);
}

QuarkusTestExtension.ExtensionState state = store.get(QuarkusTestExtension.ExtensionState.class.getName(),
QuarkusTestExtension.ExtensionState.class);
boolean wrongProfile = !Objects.equals(profile, quarkusTestProfile);
boolean wrongProfile = !Objects.equals(profile, quarkusTestProfile) || mixedWithQuarkusTest;
// we reload the test resources if we changed test class and if we had or will have per-test test resources
boolean reloadTestResources = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass)
&& (hasPerTestResources || hasPerTestResources(extensionContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import io.quarkus.test.junit.callback.QuarkusTestMethodContext;
import io.quarkus.test.junit.internal.DeepClone;
import io.quarkus.test.junit.internal.SerializationWithXStreamFallbackDeepClone;
import io.quarkus.test.junit.main.QuarkusMainTest;

public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension
implements BeforeEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, AfterEachCallback,
Expand Down Expand Up @@ -649,19 +650,25 @@ private boolean isNativeOrIntegrationTest(Class<?> clazz) {
}

private QuarkusTestExtensionState ensureStarted(ExtensionContext extensionContext) {
boolean mixedWithQuarkusMainTest = false;
ExtensionContext.Store store = getStoreFromContext(extensionContext);
Class<?> testType = store.get(IO_QUARKUS_TESTING_TYPE, Class.class);
if (testType != null) {
if (testType != QuarkusTest.class) {
throw new IllegalStateException(
"Cannot mix both @QuarkusTest based tests and " + testType.getName() + " based tests in the same run");
if (testType.equals(QuarkusMainTest.class)) {
mixedWithQuarkusMainTest = true;
} else {
throw new IllegalStateException(
"Cannot mix both @QuarkusTest based tests and " + testType.getName()
+ " based tests in the same run");
}
}
} else {
store.put(IO_QUARKUS_TESTING_TYPE, QuarkusTest.class);
}
QuarkusTestExtensionState state = getState(extensionContext);
Class<? extends QuarkusTestProfile> selectedProfile = getQuarkusTestProfile(extensionContext);
boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile);
boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile) || mixedWithQuarkusMainTest;
// we reload the test resources if we changed test class and the new test class is not a nested class, and if we had or will have per-test test resources
boolean reloadTestResources = !Objects.equals(extensionContext.getRequiredTestClass(), currentJUnitTestClass)
&& !isNested(currentJUnitTestClass, extensionContext.getRequiredTestClass())
Expand Down

0 comments on commit f997c67

Please sign in to comment.