为什么JUnit 5中默认的访问修饰符是包可见性?
在JUnit 4中,测试必须是public。
将其改为包可见性的好处是什么?
为什么JUnit 5中默认的访问修饰符是包可见性?
在JUnit 4中,测试必须是public。
将其改为包可见性的好处是什么?
public
、protected
或包私有的修饰符。public
修饰符。如果你的IDE自动生成的测试方法和测试类是public
的,那么可以保留它们的public
修饰符。public
修饰符,除非你要设计可被其他包继承的测试类,这时你需要将可重写的测试方法设置为public
或protected
。当然,接口的default
方法必须是public
的。这是JUnit 5的一个特性,它为测试类和方法提供了更好的封装性。
使Jupiter测试包可见 #679
测试类通常位于被测试类所在的相同包中:
better way is to place the tests in a separate parallel directory structure with package alignment.
main/ test/ com/ com/ xyz/ xyz/ SomeClass.java SomeClassTests.java
This approach allows test code to access all the public and package visible members of the classes under test.