JUnit5 is more tolerant regarding the visibilities of Test classes and methods than JUnit4, which required everything to be public. JUnit5 supports default package, public and protected visibility, even if it is recommended to use the default package visibility, which improves the readability of code.
But in any case, the 'private' modifier should be used. JUnit5 ignores without any warning private classes and private methods!
import org.junit.jupiter.api.Test; class MyClassTest { @Test private void test() { // Noncompliant - ignored by JUnit5 // ... } @Nested private class MyNestedClass { // Noncompliant - ignored by JUnit5 @Test void test() { // ... } } }
import org.junit.jupiter.api.Test; class MyClassTest { @Test void test() { // Noncompliant - ignored by JUnit5 // ... } @Nested class MyNestedClass { // Noncompliant - ignored by JUnit5 @Test void test() { // ... } } }