1,引入powermock依赖
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-reflect -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
2,打开要写测试用例的业务类A,然后右击,在弹出的对话框中选择“Generate”->"Test",这样生成测试用例的类
3,在测试用例的类上添加注解:
@SpringBootTest(classes = {A.class})
4,在要用到的所有的dao层接口上添加注解:
@MockBean
private DBMapper dbMapper;
5,引入业务类A
@Resource
private A a;
6,写测试方法
Mockito.when("dao数据访问层方法").thenReturn();
a.method()//调用业务类a的具体业务方法
标签:springboot2.7,dao,业务,private,测试用例,2.0,powermock
From: https://blog.51cto.com/nizuimeiabc1/6416718