【问题标题】:How to mock ATG RqlStatement如何模拟 ATG RqlStatement
【发布时间】: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 注释。现在为我工作

标签: mockito powermock atg


【解决方案1】:

添加 @PrepareForTest 注释 .working for me now

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多