Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Mockito 中,如果你想让一个 void 方法什么都不做,你可以这样做:
doNothing().when(_mockedClass).voidMethod();
有没有办法用 JMockit 做到这一点?
我似乎找不到任何关于它的东西。我一直在尝试切换到 JMockit,但在查找我们使用 Mockito 所做的一些事情的文档时遇到了麻烦。我怀疑它们都以一种或另一种形式存在,只是很难找到它们,所以我想我会开始在这里一次问一个问题,希望有简单的答案!谢谢!
就像 Mockito 一样,实际上,如果你想要一个方法什么都不做,那么就不要记录对它的期望。或者,您可以使用 no 记录期望result,但实际上没有必要(或指向它)。
result
(只有在使用严格期望(with )时才不会出现这种情况new StrictExpectations() {{ ... }},在这种情况下,所有方法调用都需要考虑在内。)
new StrictExpectations() {{ ... }}