Skip to content

[java] JUnit5TestShouldBePackagePrivate is not applied when @Test method is only present in parent class #5477

@altaiezior

Description

@altaiezior

Affects PMD Version: 7.9.0

Rule: JUnit5TestShouldBePackagePrivate

Description:
I have a base class which has the test method and there are a lot of child classes to it which just provides parent test case required arguments, if these child classes are not package private, pmd rule doesn't report it as violation because these classes doesn't contain a @Test method.

Code Sample demonstrating the issue:

public abstract class AbstractModuleTest {
    @Test
    void testModule() {
        assertEquals(value(), value());
    }

    protected abstract int value();
}

public class ModuleImplTest extends AbstractModuleTest {
    @Override
    void value() {
        return 1;
    }
}

Expected outcome:

In the above case ModuleImplTest is not package private and should be reported.

Running PMD through: maven

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions