我有一个 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:如何取消模拟方法?
发布评论