你好!在spring-boot中使用mybatis-plus时, 为持久层编写相关单元测试, 希望能像原生mybatis集成mybatis-spring-boot-starter-test, 然后通过以下方式启动一个测试:

@RunWith(SpringRunner.class)
@MybatisTest
public class CityMapperTest {

    @Autowired
    private CityMapper cityMapper;

    @Test
    public void findByStateTest() {
        City city = cityMapper.findByState("CA");
        assertThat(city.getName()).isEqualTo("San Francisco");
        assertThat(city.getState()).isEqualTo("CA");
        assertThat(city.getCountry()).isEqualTo("US");
    }

}

这样的好处是: 只会加载mybatis相关的自动配置, 加快单元测试速度、自动替换数据源为内存数据库(H2...) 文档详细描述: http://mybatis.org/spring-boot-starter/mybatis-spring-boot-test-autoconfigure/

Comment From: miemieYaho

使用 3.3.3.1-SNAPSHOT mybatis-plus-boot-starter-test ,注解 MybatisPlusTest,逻辑和mybatis的一样,你试试