Java

Java

Made by DeepSource

JUnit5 test classes and methods should be package-private JAVA-W1058

Anti-pattern
Minor
Autofix

JUnit5 test classes and methods should be package-private.

Unlike JUnit4 which required all the test classes and methods to be declared public, in JUnit5 they can be anything but private. To enforce maximum encapsulation, it is recommended to declare test classes and methods as package-private.

Bad Practice

public class MyTest {
    @Test
    public void testThis() {
        // ..test things
    }
}

Recommended

Consider making your test classes and methods package-private.

class MyTest {
    @Test
    void testThis() {
        // ..test things
    }
}

References