在使用Mockito时,如果要模拟一个无返回值的方法,可以使用doNothing()方法。例如:
// 创建一个mock对象SomeClass someClassMock = Mockito.mock(SomeClass.class);// 模拟无返回值的方法Mockito.doNothing().when(someClassMock).voidMethod();这样就可以模拟SomeClass类中的voidMethod()方法,使其在被调用时不做任何操作。
上一篇:Delphi的优点和缺点有哪些
下一篇:android内存溢出的原因有哪些
java









