【发布时间】:2021-06-26 11:02:56
【问题描述】:
我正在为 Spring Boot 项目中的服务类编写单元测试。当我对正在测试的类进行自动装配时,测试在哪里正常运行,而当我使用 @MockBean insead of @Autowire 时它会失败。
@SpringBootTest
class SignupServiceTest {
@Autowired SignupService signupService;
@MockBean DSService dsService;
@MockBean SignupHelper signupHelper;
@MockBean SessionHelper sessionHelper;
@MockBean CommonService commonService;
可以帮助我解决差异以及 @MockBean 失败的原因。还有一种方法可以在 mockito 中模拟自动装配类(当前类)的方法。
【问题讨论】:
标签: spring-boot junit mockito spring-test spring-boot-test