{"record":{"id":"89121d664ff8e262","repo":"JetBrains/intellij-community","slug":"no-junit-jar-in-0","errorCode":null,"errorMessage":"No junit.jar in {0}","messagePattern":"No junit\\.jar in (.+?)","errorType":"exception","errorClass":"NoJUnitException","httpStatus":null,"severity":"error","filePath":"java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java","lineNumber":521,"sourceCode":"  }\n\n  public static @NotNull PsiClass getTestCaseClass(final SourceScope scope) throws NoJUnitException {\n    if (scope == null) throw new NoJUnitException();\n    return getTestCaseClass(scope.getLibrariesScope(), scope.getProject());\n  }\n\n  public static void checkTestCase(SourceScope scope, Project project) throws NoJUnitException {\n    if (scope == null) throw new NoJUnitException();\n    PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(\"junit.framework\");\n    if (aPackage == null || aPackage.getDirectories(scope.getLibrariesScope()).length == 0) {\n      throw new NoJUnitException();\n    }\n  }\n\n  private static @NotNull PsiClass getTestCaseClass(final @NotNull GlobalSearchScope scope, final @NotNull Project project)\n    throws NoJUnitException {\n    PsiClass testCaseClass = getTestCaseClassOrNull(scope, project);\n    if (testCaseClass == null) throw new NoJUnitException(scope.getDisplayName());\n    return testCaseClass;\n  }\n\n  private static @Nullable PsiClass getTestCaseClassOrNull(final @NotNull GlobalSearchScope scope, final @NotNull Project project) {\n    return JavaPsiFacade.getInstance(project).findClass(TEST_CASE_CLASS, scope);\n  }\n\n  public static boolean isTestMethodOrConfig(@NotNull PsiMethod psiMethod) {\n    final PsiClass containingClass = psiMethod.getContainingClass();\n    if (containingClass == null) {\n      return false;\n    }\n    if (isTestMethod(PsiLocation.fromPsiElement(psiMethod), false)) {\n      if (containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) {\n        final boolean[] foundNonAbstractInheritor = new boolean[1];\n        ClassInheritorsSearch.search(containingClass).forEach(psiClass -> {\n          if (!psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {\n            foundNonAbstractInheritor[0] = true;","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java#L503-L539","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"<!-- before: module pom has no junit -->\n<!-- after -->\n<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency>","handlingStrategy":"try-catch","validationCode":"// check resolvability first and report the scope name yourself\nPsiClass c = JavaPsiFacade.getInstance(project).findClass(\"junit.framework.TestCase\", scope);\nif (c == null) return error(\"JUnit missing in scope: \" + scope.getDisplayName());","typeGuard":null,"tryCatchPattern":"try {\n  PsiClass tc = JUnitUtil.getTestCaseClass(scope);\n} catch (NoJUnitException e) {\n  // message names the scope — use it to fix the exact module's dependencies\n  logAndOfferQuickFix(e.getMessage());\n}","preventionTips":["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'"],"tags":["junit","classpath","scope-name","test-framework","maven"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}