小编Ven*_*kat的帖子

这里有什么区别 - @Autowired 和 @MockBean

我正在为 Spring Boot 项目中的服务类编写单元测试。当我自动装配正在测试的类时,测试可以正确运行,而当我使用 @MockBean 而不是 @Autowire 时,测试会失败。

@SpringBootTest
class SignupServiceTest {

  @Autowired SignupService signupService;

  @MockBean DSService dsService;

  @MockBean SignupHelper signupHelper;

  @MockBean SessionHelper sessionHelper;

  @MockBean CommonService commonService;
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决差异以及 @MockBean 失败的原因吗?还有一种方法可以在mockito中模拟自动装配类(当前类)的方法。

junit spring-test mockito spring-boot spring-boot-test

-1
推荐指数
1
解决办法
3456
查看次数