Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly allow mixing @QuarkusTest and @QuarkusMainTest #28499

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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