如何在Junit5中测试私有/受保护的方法?

发布于 2025-02-08 23:41:08 字数 133 浏览 1 评论 0原文

有没有办法在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月棠 2025-02-15 23:41:08

在Junit 4测试中,私人方法可能表明应将这些方法移至另一类以促进可重复使用性。

我认为这个陈述没有前三个词。在这方面,Junit 4和5之间没有区别;更重要的是,测试框架与它完全无关。

因此,我建议您同等地进行:要么通过公共接口间接测试私人方法,要么将其提取到可以独立行使的地方。

In JUnit 4 testing private methods may be an indication that those methods should be moved into another class to promote reusability.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文