如何在Spring Boot中测试组件/Bean [英] How to test a component / bean in Spring Boot

查看:129
本文介绍了如何在Spring Boot中测试组件/Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在Spring Boot应用程序中测试组件/bean,请 Spring Boot文档的测试部分提供了很多信息和多种方式: @Test@SpringBootTest@WebMvcTest@DataJpaTest以及许多其他方式.
为什么提供这么多方式? 如何决定青睐的方式?
我是否应该将以Spring Boot测试注释(例如@SpringBootTest@WebMvcTest@DataJpaTest)注释的测试类视为集成测试?

To test a component/bean in a Spring Boot application, the testing part of the Spring Boot documentation provides much information and multiple ways : @Test, @SpringBootTest, @WebMvcTest, @DataJpaTest and still many other ways.
Why provide so many ways ? How decide the way to favor ?
Should I consider as integration tests my test classes annotated with Spring Boot test annotations such as @SpringBootTest, @WebMvcTest, @DataJpaTest ?

PS:之所以创建此问题,是因为我注意到许多开发人员(即使是经验丰富的开发人员)也不会因为使用注释而不是注释而产生后果.

PS : I created this question because I noticed that many developers (even experienced) don't get the consequences to use an annotation rather than another.

推荐答案

TL-DR

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