gpt4 book ai didi

java - SpringRunner 与 SpringBootTest

转载 作者:行者123 更新时间:2023-11-30 05:49:33 26 4
gpt4 key购买 nike

在单元测试中,@Runwith(SpringRunner.class) & @SpringBootTest有什么区别?

你能给我解释一下每一个的用例吗?

最佳答案

@RunWith(SpringRunner.class) :您需要此注解来启用 spring boot 功能,如 @Autowire@MockBean 等。 . 在 junit 测试期间

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 :该注解用于加载完整的应用程序上下文以进行端到端集成测试

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

关于java - SpringRunner 与 SpringBootTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58901288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com