diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java index 95c90923c412e..aeb551a1cd7b7 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java @@ -64,13 +64,18 @@ private void ensurePrepared(ExtensionContext extensionContext, 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); @@ -78,7 +83,7 @@ private void ensurePrepared(ExtensionContext extensionContext, 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 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())