【发布时间】:2013-08-12 07:38:50
【问题描述】:
在我的 ATG Droplet 中,我正在从存储库中获取记录。现在,当我尝试模拟 RQLStatement 时,它会抛出 org.mockito.exceptions.misusing.MissingMethodInvocationException
以下是我试图模拟的语句:
final RepositoryView view = this.getRepository().getView("product");
final RqlStatement statement = RqlStatement.parseRqlStatement("id = ?0");
prodItems = statement.executeQuery(view, params);
我使用了 mockito 和 powermockito 但它不起作用
PowerMockito.mockStatic(RqlStatement.class);
PowerMockito.when(RqlStatement.parseRqlStatement("id =?0")).thenReturn(this.statementmock);
Mockito.when(this.statementmock.executeQuery(this.viewMock, params)).thenReturn(new RepositoryItem[4]);
【问题讨论】:
-
什么是完整的例外?你也加了
@PrepareForTest注解吗? -
不要模拟你不拥有的类型,这会导致很多问题,有些可能会让你在生产中措手不及,仍然在绿色的地方进行测试...说真的,您最好编写尝试模拟此 Oracle 子系统的集成测试。您绝对应该阅读互联网对此的说法,例如this article
-
感谢 radimpe。我忘了添加 @PrepareForTest 注释。现在为我工作