mockito:如何取消模拟方法? [英] mockito : how to unmock a method?

查看:516
本文介绍了mockito:如何取消模拟方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JUnit 类,有不同的方法来执行不同的测试。

I have a JUnit class with different methods to perform different tests.

我使用 Mockito 来创建实际实例上的间谍,然后覆盖一些与我执行的实际测试无关的方法。

I use Mockito to create a spy on real instance, and then override some method which is not relevant to the actual test I perform.

有没有办法,只是为了清理之后我以防万一我的测试后运行的其他一些测试也使用相同的实例,可能会执行一个模拟的方法,他们没有要求模拟,去模拟一个方法?

Is there a way, just for the sake of cleaning up after me in case some other tests that run after my tests also use the same instances and might execute a mocked method they didn't ask to mock, to un-mock a method?

说我有一个名为'wareHouseSpy'的间谍对象

说我覆盖方法 isSomethingMissing

doReturn(false).when(wareHouseSpy).isSomethingMissing()

什么是正确的方法来取消覆盖,并使间谍恢复正常,即使 isSomethingMissing 的下一次调用运行真正的方法?

What will be the right way to un-override, and bring things back to normal on the spy i.e make the next invokation of isSomethingMissing to run the real method?

类似

doReturn(Mockito.RETURN_REAL_METHOD).when(wareHouseSpy).isSomethingSpy()

或者

Mockito.unmock(wareHouseSpy)

谁知道?我在那个区域找不到任何东西

Who knows? I couldn't find nothing in that area

谢谢!

Assaf

推荐答案

我认为

Mockito.reset(wareHouseSpy)

会这样做。

这篇关于mockito:如何取消模拟方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆