log.info(🍺);|

大哥超帅

园龄:5年11个月粉丝:2关注:5

Mockito mock 静态 void 方法

        MockedStatic<SpringContextUtils> utils = Mockito.mockStatic(SpringContextUtils.class);
        utils.when(() ->SpringContextUtils.publishEvent(any())).thenAnswer(invocation -> null);
...
//最后需要关闭
utils.close();

maven

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.7.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-inline</artifactId>
            <version>3.7.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>3.7.7</version>
            <scope>test</scope>
        </dependency>

本文作者:大哥超帅

本文链接:https://www.cnblogs.com/funkboy/p/17145315.html

版权声明:本作品采用CC 4.0 BY-SA版权协议许可协议进行许可。

posted @   大哥超帅  阅读(3241)  评论(1编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起