MockBean required a single bean, but 2 were found(@MockBean, @SpyBean)

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);
    }

}
posted @ 2023-03-02 20:05  神一样的存在  阅读(81)  评论(0编辑  收藏  举报