Mapper接口:

package sample.mybatis.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import sample.mybatis.domain.City;

@Mapper
public interface CityMapper {

    @Select("SELECT * FROM CITY WHERE state = #{state}")
    City findByState(@Param("state") String state);

}

测试类:

package sample.mybatis.mapper;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import sample.mybatis.domain.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

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

}

这样可以在大型项目测试类中不需要使用@SpringBootTest启动整个项目,只配置MybatisPlus部分直接测试Mapper 参考mybatis-spring-boot-test-autoconfigure

Comment From: qmdx

https://github.com/baomidou/mybatis-plus/tree/3.0/mybatis-plus-boot-starter-test 能否满足?

Comment From: Ubisoft-potato

https://github.com/baomidou/mybatis-plus/tree/3.0/mybatis-plus-boot-starter-test 能否满足?

感谢,可以满足