问题描述
在单元测试中,@Runwith(SpringRunner.class)
和& amp;之间有什么区别? @SpringBootTest
?
In unit test, what are the differences between @Runwith(SpringRunner.class)
& @SpringBootTest
?
您能向我解释每个案例的用例吗?
Can you explain to me the use cases of each one?
推荐答案
@RunWith(SpringRunner.class):您需要此批注仅启用诸如@Autowire
,@MockBean
之类的spring boot功能.等.在junit测试期间
@RunWith(SpringRunner.class) : You need this annotation to just enable spring boot features like @Autowire
, @MockBean
etc.. during junit testing
@SpringBootTest::此批注用于加载完整的应用程序上下文以进行端到端集成测试
@SpringBootTest : This annotation is used to load complete application context for end to end integration testing
以下是这两种情况下带有清晰示例的文章 Baeldung
Here is the article with clear examples on both scenarios Baeldung
这篇关于SpringRunner vs SpringBootTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!