我在test/resources/mockito-extensions中的org.mockito.plugins.MockMaker文件中添加了mock-maker-inline文本。
在我的测试用例中,我正在使用:
System system = mock(System.class);
when(system.getProperty("flag")).thenReturn("true");`
但我遇到了以下异常:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
感谢您的建议。
System.setProperty("flag", "true");
应该可以正常工作。 - Andrew S