小编Rag*_*ghu的帖子

如何使用 Mockito 模拟 System.getProperty

我在 org.mockito.plugins.MockMaker 文件中添加了 mock-maker-inline 文本并将其放置在 test/resources/mockito-extensions

在我的测试用例中,我使用:

System system = mock(System.class);
when(system.getProperty("flag")).thenReturn("true");`
Run Code Online (Sandbox Code Playgroud)

但我收到以下异常:

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.
Run Code Online (Sandbox Code Playgroud)

感谢任何建议

java unit-testing mockito

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×1

mockito ×1

unit-testing ×1