快速测试
自动导入 MyBatis-Plus 测试所需相关配置,通过 @MybatisPlusTest
注解快速配置测试类。
# 示例工程
源码:👉 mybatis-plus-boot-starter-test (opens new window)
# 使用教程
# 添加测试依赖
Maven:
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter-test</artifactId>
<version>latest-version</version>
</dependency>
1
2
3
4
5
2
3
4
5
Gradle:
compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter-test', version: 'latest-version'
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();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
帮助我们改善此页面! (opens new window)
上次更新: 2022/01/16, 21:55:54