junit 5:@springboottest和@extendwith(springextension.class)之间的差异
使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您绝对可以使用
@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.