Skip to content

Commit

Permalink
SmartDirtiesTestsHolder diagnostics for IDEA
Browse files Browse the repository at this point in the history
  • Loading branch information
seregamorph committed Jan 26, 2024
1 parent c534114 commit 0108b34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ final class JUnitPlatformSupport {
private static final boolean JUNIT5_JUPITER_API_PRESENT = isClassPresent(
"org.junit.jupiter.api.extension.ExtendWith");

private static final boolean JUNIT4_IDEA_TEST_RUNNER_PRESENT = isClassPresent(
"com.intellij.junit4.JUnit4IdeaTestRunner");

static boolean isJUnitVintageEnginePresent() {
return JUNIT_VINTAGE_ENGINE_PRESENT;
}
Expand All @@ -25,6 +28,10 @@ static boolean isJunit5JupiterApiPresent() {
return JUNIT5_JUPITER_API_PRESENT;
}

static boolean isJUnit4IdeaTestRunnerPresent() {
return JUNIT4_IDEA_TEST_RUNNER_PRESENT;
}

private static boolean isClassPresent(String className) {
return ClassUtils.isPresent(className, JUnitPlatformSupport.class.getClassLoader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ public static int lastClassPerConfigSize() {

static boolean isLastClassPerConfig(Class<?> testClass) {
if (lastClassPerConfig == null) {
if (JUnitPlatformSupport.isJUnit4IdeaTestRunnerPresent()) {
System.err.println("The test is started via IDEA old JUnit 4 runner (not vintage), " +
"the Smart DirtiesContext behaviour is disabled.");
if (!JUnitPlatformSupport.isJunit5JupiterApiPresent()) {
System.err.println("If you add org.junit.jupiter:junit-jupiter-api test dependency, \n" +
"it will allow to run packages/modules with tests with Smart DirtiesContext semantics via IDEA. See \n" +
"https://youtrack.jetbrains.com/issue/IDEA-343605/junit-vintage-engine-is-not-preferred-by-default\n" +
"for details.");
}
return false;
}
throw new IllegalStateException("lastClassPerConfig is not initialized");
}
Boolean isLastClassPerConfig = lastClassPerConfig.get(testClass);
Expand Down

0 comments on commit 0108b34

Please sign in to comment.