Skip to content

[java] JUnitJupiterTestShouldBePackagePrivate: False negative when the only tests are in a @Nested class #6736

Closed

Description

@UncleOwen

Affects PMD Version: 7.25.0

Rule: JUnitJupiterTestShouldBePackagePrivate

Code Sample demonstrating the issue:

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public class FooTest extends SuperTest {
}

class SuperTest {
    @Nested
    class NestedClass {
        @Test
        void testFoo() {
        }
    }
}

Expected outcome: PMD should report a violation at line 4, but doesn't. This is a false-negative.

Diagnosis: TestFrameworksUtil.isJUnit5Class() only checks for test methods, not for nested test classes. For that, we need a JTypeMirror.streamNestedClasses() (similar to JTypeMirror.streamMethods())

Running PMD through: Maven

Activity

  1. added
    in:type-resolution
    a:false-negative
    on May 29, 2026
  2. changed the title [-][java] JUnitJupiterTestShouldBePackagePrivate: False negative when the only tests are in a @Nested class inside a superclass[/-] [+][java] JUnitJupiterTestShouldBePackagePrivate: False negative when the only tests are in a @Nested class[/+] on May 30, 2026
  3. added a commit that references this issue on Jun 23, 2026
    cabc962
  4. added this to the 7.26.0 milestone on Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativein:type-resolution

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions