SpringRunner vs SpringBootTest [英] SpringRunner vs SpringBootTest
问题描述
在单元测试中,@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
用于在Spring Boot测试功能和JUnit之间建立桥梁.每当我们在JUnit测试中使用任何Spring Boot测试功能时,都将需要此批注.
is used to provide a bridge between Spring Boot test features and JUnit. Whenever we are using any Spring Boot testing features in our JUnit tests, this annotation will be required.
@SpringBootTest::此批注用于加载完整的应用程序上下文以进行端到端集成测试
@SpringBootTest : This annotation is used to load complete application context for end to end integration testing
当我们需要引导整个容器时,可以使用@SpringBootTest批注.注释通过创建将在我们的测试中使用的ApplicationContext起作用.
The @SpringBootTest annotation can be used when we need to bootstrap the entire container. The annotation works by creating the ApplicationContext that will be utilized in our tests.
以下是这两种情况下带有清晰示例的文章 Baeldung
Here is the article with clear examples on both scenarios Baeldung
这篇关于SpringRunner vs SpringBootTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!