我正在为 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中模拟自动装配类(当前类)的方法。