junit 5:@springboottest和@extendwith(springextension.class)之间的差异

发布于 2025-02-11 10:29:48 字数 232 浏览 0 评论 0原文

使用junit5进行测试,我可以在没有@springboottest的情况下仅使用@ExtendWith(SpringExtension.class)吗? 一些资源说,@springboottest已经包括@ExtendWith(SpringExtension.class),这是正确的吗? 当我仅使用@ExtendWith(SpringExtension.class)进行测试时,我注意到测试很轻,并且不加载整个应用程序上下文被认为是完整还是正确?

Testing with Junit5, Can I use only @ExtendWith(SpringExtension.class) without @SpringBootTest ?
Some resources say that @SpringBootTest already include @ExtendWith(SpringExtension.class), is this correct ?
When I run the test with @ExtendWith(SpringExtension.class) only, I notice that the test is very light and doesn't load the entire application context, but I'm not sure if I don't use @SpringBootTest my unit test is considered complete or correct ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

可可 2025-02-18 10:29:48

是的,您绝对可以使用@ExtendWith(SpringExtension.class),而无需加载@springbottemest包含的整个应用程序上下文。正如您所说,如果您只想用@mockbean模拟豆子,这是一种轻巧的方法。 @springboottest实际上包括@ExtendWith(SpringExtension.class),但对于您要实现的目标可能会过高。

Yes, you can definitely use @ExtendWith(SpringExtension.class) without loading the entire application context that is included with @SpringBootTest. As you say it's a lighter weight approach if you just want to mock beans with @MockBean. @SpringBootTest does in fact include @ExtendWith(SpringExtension.class) but it may be overkill for what you are trying to achieve.

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