PowerMockito验证从不调用静态方法

编程入门 行业动态 更新时间:2024-10-26 02:35:21
本文介绍了PowerMockito验证从不调用静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个JUnit测试,以验证是否在方法流中从未调用静态方法(MyClass.myMethod()).我试图做这样的事情:

I am writing a JUnit test to verify that a static method (MyClass.myMethod()) is never invoked in the method flow. I tried doing something like this:

PowerMockito.verifyStatic(Mockito.never()); MyClass.myMethod(Mockito.any());

这样做会收到UnfinisedVerificationException.如何测试MyClass.class在方法执行中没有任何交互?

In doing so I receive an UnfinisedVerificationException. How do I test that MyClass.class has no interactions whatsoever in the method execution?

推荐答案

如果尚未模拟该类,但您正在尝试验证其静态方法的调用,则会发生UnfinishedVerificationException.

UnfinishedVerificationException will occur if the Class is not mocked yet but you are trying to verify the invocation of its static method.

PowerMockito.mockStatic(MyClass.class); underTest.testMethod(); PowerMockito.verifyStatic(Mockito.never()); MyClass.myMethod(Mockito.any()); . . .

如果流程从未遇到对MyClass.myMethod()

更多推荐

PowerMockito验证从不调用静态方法

本文发布于:2023-10-31 07:15:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545401.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   方法   PowerMockito

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!