I'm currently studying a JUnit 5 book and I need assistance in understanding this line:
A test method can be either protected or package protected. The preferred is to use package protected as that leads to less typing.
If the citation is accurate, it is wrong. A Jupiter test method (there’s no such thing as a JUnit 5 test method) can be anything but private
, so it can be public
, protected
or package private. Package private means that it has no accessibility modifier.
That means that running the following test class:
import org.junit.jupiter.api.Test;
class MyTests {
@Test
public void test1() {
}
@Test
protected void test2() {
}
@Test
void test3() {
}
@Test
private void test4() {
}
}
will execute test1, test2 and test3, but not test4. test3 being the preferred one.
Mind that the same holds for the class' accessibility modifier: package private and public are possible. Private classes are not being executed, protected classes do not exist in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With