PowerMock:默认情况下如何 return null?

PowerMock: how to return null by default?

我正在使用 PowerMock、EasyMock 组合。

如果没有另外指定,我如何使每个模拟对象默认为 return 'null'?

现在,我必须 'expect'(或在 mockito 世界中 'when')模拟对象的每个方法。

作为Rogério commented, you can use EasyMock#createNiceMock:

Creates a mock object that implements the given interface, order checking is disabled by default, and the mock object will return 0, null or false for unexpected invocations.

EasyMock#niceMock:

Creates a mock object that implements the given interface, order checking is disabled by default, and the mock object will return 0, null or false for unexpected invocations.