如何在Junit5中测试私有/受保护的方法?
有没有办法在Junit5中测试私有/受保护的方法?
在Junit 4测试中,私有方法可能表明应将这些方法移至另一个类以促进可重复性。对于受保护的方法,应将测试与正在测试的类中放置在相同的软件包中。
junit5是什么情况?
Is there a way to test private/ protected methods in JUnit5?
In JUnit 4 testing private methods may be an indication that those methods should be moved into another class to promote reusability. And for protected methods tests should be placed in the same package as the classes under test.
What is the case in JUnit5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这个陈述没有前三个词。在这方面,Junit 4和5之间没有区别;更重要的是,测试框架与它完全无关。
因此,我建议您同等地进行:要么通过公共接口间接测试私人方法,要么将其提取到可以独立行使的地方。
I’d argue that this statement holds without the first three words. There’s no difference between JUnit 4 and 5 in this regard; even more, the testing framework has nothing to do with it at all.
So I recommend that you proceed equally: Either test the private method indirectly through the public interface or extract it to a place where it can be exercised independently.