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 springboot powermock 业务springboot2 springboot powermock业务 springboot2 springboot2 springboot springboot2 springboot swagger3 swagger springboot2 springboot mybatis springboot2 springboot lettuce redis springboot2 springboot spring3 spring springboot2 springboot后台 管理系统 springboot2 springcache springboot springboot2 springboot mybatis3 mybatis