MyBatis-Plus 快速入门-快速测试
自动导入 MyBatis-Plus 测试所需相关配置,通过 @MybatisPlusTest
注解快速配置测试类。
添加测试依赖
Maven:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter-test</artifactId>
<version>3.5.1</version>
</dependency>
Gradle:
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter-test', version: '3.5.1'
编写测试用例
通过 @MybatisPlusTest
可快速编写 Mapper 对应的测试类,实现快速测试代码
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.assertj.core.api.Assertions.assertThat;
@MybatisPlusTest
class MybatisPlusSampleTest {
@Autowired
private SampleMapper sampleMapper;
@Test
void testInsert() {
Sample sample = new Sample();
sampleMapper.insert(sample);
assertThat(sample.getId()).isNotNull();
}
}