Mockito早期一直不支持静态方法mock测试,需要借助PowerMockito实现静态方法mock测试。
自mockito 3.4.0开始,支持静态方法mock测试,用法简单方便。下面示例演示有参和无参的静态方法调用mock测试和验证。
本文测试环境:
jdk11 + mockito4.0.0 + junit5 + spring-boot2.6.5
maven依赖:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency&

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



