woj*_*902 11 java encapsulation package-private junit5
为什么JUnit 5 package-private中的默认访问修饰符是?
JUnit 4中的测试必须是公开的。
将其更改为程序包专用有什么好处?
Sam*_*nen 12
为什么JUnit 5 package-private中的默认访问修饰符是?
It's not the "default". There technically is no default. Rather, in JUnit Jupiter you have a choice: public, protected or package-private.
What is the benefit of changing it to package-private?
The benefit is that you don't have type public anymore. If your IDE automatically generates test methods and test classes for you that are public, feel free to leave them public.
But... if you are typing in the methods on your own, then just leave off public unless you are designing your test classes for subclassing from other packages, in which case you'd want to make your overrideable test methods either public or protected. And of course, interface default methods must be public.
Long story, short: we (the JUnit 5 team) believe in the principle "Less is more", meaning the less you have to type to achieve your goal, the better!
这是 JUnit 5特性,它为测试类和方法产生更好的封装
将 Jupiter 测试包设为私有 #679
测试类主要位于测试类的同一个包中:
更好的方法是将测试放置在具有包对齐的单独并行目录结构中。
Run Code Online (Sandbox Code Playgroud)main/ test/ com/ com/ xyz/ xyz/ SomeClass.java SomeClassTests.java这种方法允许测试代码访问被测类的所有公共和包可见成员。
| 归档时间: |
|
| 查看次数: |
783 次 |
| 最近记录: |