SpringRunner 与 SpringBootTest [英] SpringRunner vs SpringBootTest

查看:19
本文介绍了SpringRunner 与 SpringBootTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单元测试中,@Runwith(SpringRunner.class) & 有什么区别?@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) : 你需要这个注解来启用 spring boot 特性,比如 @Autowire@MockBean 等等.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 与 SpringBootTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆