java - 我如何模拟 Ignition.start()
问题描述
由于各种原因,我的单元测试环境无法访问启动 ignite 所需的环境。我不需要 ignite 来开始测试,我希望代码忽略对 Ignition.start() 的调用。我怎么做?
我尝试过模拟点火,但是当我尝试模拟 start() 方法时,它会引发错误。
when(ignitionMock.start())
这会导致以下错误:
org.mockito.exceptions.misusing.MissingMethodInvocationException: when() 需要一个参数,该参数必须是“模拟的方法调用”。例如:when(mock.getArticles()).thenReturn(articles);
此外,此错误可能会出现,因为: 1. 您存根以下任一方法:final/private/equals()/hashCode() 方法。这些方法不能被存根/验证。不支持在非公共父类上声明的模拟方法。2. 在 when() 中,您不会在 mock 上调用方法,而是在其他对象上调用方法。
解决方案
你可以使用doNothing()
:
doNothing().when(ignitionMock).start();
推荐阅读
- javascript - 在 node.js 中提供 HTML 文件
- java - 忽略依赖项中的实体持久性
- java - 如何使用拦截器在 CORBA 中操作发送到远程对象的参数
- c# - 如何合并两个表达式
- python - Plotly-Dash:想要两个堆叠的条形图从单个 df 列并排
- android-source - 为 Hikey970 构建 AOSP 时出错
- sql - 我想更改应用程序清单文件上的数据库服务器
- javascript - 如何使用正则表达式从字符串中删除以 www.*** 开头的 url?
- sql - 将包括数字在内的数据从 Excel 导入 SQL DB
- middleman-4 - 带有中间人的 yml 文件中的新段落