MockBean required a single bean, but 2 were found.
mybatis-spring: 2.0.5
mockito: 3.3.3
spring: 2.3.2.RELEASE
————————————————
原文鏈接:https://blog.csdn.net/eventer123/article/details/110861566
總之mybatis-spring
:如果使用了2.0.5版本就不行,比如下面的代碼就會報錯,但是如果高於2.0.5版本就沒問題:
@SpringBootTest
class MockTest {
@SpyBean
private UserService userService;
@SpyBean
private UserMapper userMapper;
@Test
void currTest() {
Mockito.doReturn(new User().setId(100L).setName("ddd").setPassword("mmm")).when(userMapper).findByNameAndPassword("w.dehai", "123456");
User login = userService.login("w.dehai", "123456");
System.err.println(login);
}
}