JetBrains/intellij-community · error · NoJUnitException
No junit.jar in {0}
Error message
No junit.jar in {0} What it means
The private core overload JUnitUtil.getTestCaseClass(GlobalSearchScope, Project) throws NoJUnitException with a parameterized message ('No junit.jar in {0}') when JavaPsiFacade.findClass(TEST_CASE_CLASS = junit.framework.TestCase, scope) returns null. The {0} placeholder is filled with scope.getDisplayName(), telling the user exactly which scope lacks JUnit.
Source
Thrown at java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java:521
}
public static @NotNull PsiClass getTestCaseClass(final SourceScope scope) throws NoJUnitException {
if (scope == null) throw new NoJUnitException();
return getTestCaseClass(scope.getLibrariesScope(), scope.getProject());
}
public static void checkTestCase(SourceScope scope, Project project) throws NoJUnitException {
if (scope == null) throw new NoJUnitException();
PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("junit.framework");
if (aPackage == null || aPackage.getDirectories(scope.getLibrariesScope()).length == 0) {
throw new NoJUnitException();
}
}
private static @NotNull PsiClass getTestCaseClass(final @NotNull GlobalSearchScope scope, final @NotNull Project project)
throws NoJUnitException {
PsiClass testCaseClass = getTestCaseClassOrNull(scope, project);
if (testCaseClass == null) throw new NoJUnitException(scope.getDisplayName());
return testCaseClass;
}
private static @Nullable PsiClass getTestCaseClassOrNull(final @NotNull GlobalSearchScope scope, final @NotNull Project project) {
return JavaPsiFacade.getInstance(project).findClass(TEST_CASE_CLASS, scope);
}
public static boolean isTestMethodOrConfig(@NotNull PsiMethod psiMethod) {
final PsiClass containingClass = psiMethod.getContainingClass();
if (containingClass == null) {
return false;
}
if (isTestMethod(PsiLocation.fromPsiElement(psiMethod), false)) {
if (containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
final boolean[] foundNonAbstractInheritor = new boolean[1];
ClassInheritorsSearch.search(containingClass).forEach(psiClass -> {
if (!psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
foundNonAbstractInheritor[0] = true;View on GitHub (pinned to be881553f2)
Solutions
- Read the scope name in the message and add junit:junit (test scope) to that exact module
- For Maven: check the module's pom for a junit dependency with scope test; for Gradle: testImplementation in that module's build script
- Confirm the run configuration 'Use classpath of module' selection matches the module that owns the test
- Re-sync the build system afterwards
Example fix
<!-- before: module pom has no junit --> <!-- after --> <dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency>
Defensive patterns
Strategy: try-catch
Validate before calling
// check resolvability first and report the scope name yourself
PsiClass c = JavaPsiFacade.getInstance(project).findClass("junit.framework.TestCase", scope);
if (c == null) return error("JUnit missing in scope: " + scope.getDisplayName()); Try / catch
try {
PsiClass tc = JUnitUtil.getTestCaseClass(scope);
} catch (NoJUnitException e) {
// message names the scope — use it to fix the exact module's dependencies
logAndOfferQuickFix(e.getMessage());
} Prevention
- Use the scope name in the message to target the right module's build file
- Keep JUnit dependencies per-module in multi-module builds, not just in the root
- Verify dependency scope is 'test', not 'provided'/'compileOnly'
When it happens
Trigger: Any of the public getTestCaseClass overloads resolving a valid scope, then failing to find junit.framework.TestCase in it — e.g. 'module 'foo'' scope shown in the message because that module's runtime scope has no junit.jar.
Common situations: Diagnosing which module/scope is missing JUnit: the message names the module. Typical when tests live in a module whose dependencies were pruned, or when Gradle/Maven put junit into another configuration.
Related errors
- No junit.jar
- Malformed exclusion, 'groupId:artifactName' format is expect
- '{0}' is disabled when per-module working directory is confi
- {0} is disabled in fork mode.<br/>Change fork mode to <no
- No external project config file is defined
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/89121d664ff8e262.
Report an issue: GitHub.