缺少方法调用验证(模拟),但有一个?(Missing method call for verify(mock), but there is one?)
介绍
我正在尝试进行一项测试,验证(使用Mockito v1.9.5的
verify
)在执行传递Foo.deinit()
之后调用接口Bar
带有签名deinit()
的方法,并且我'我遇到错误我真的不明白。这是我试图运行的
FooTest.java
:@RunWith(JukitoRunner.class) public class FooTest { @Inject private Foo foo; @Inject private Bar bar; public static class TestModule extends JukitoModule { @Override protected void configureTest() { bind(Foo.class).to(FooImpl.class); bind(Bar.class).to(BarImpl.class); bindSpy(BarImpl.class); } } @Test public void testDeinit() { foo.init(mock(Baz.class)); foo.deinit(); verify(bar).deinit(); } @After public void validate() { validateMockitoUsage(); //line YY } }
运行此时,
testDeinit()
失败并出现以下错误:org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here: -> at redacted.impl.BarImpl.deinit(BarImpl.java:XX) Example of correct verification: verify(mock).doSomething() Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods. Those methods *cannot* be stubbed/verified. at redacted.impl.FooTest.validate(FooTest.java:YY) at org.jukito.InjectedStatement.evaluate(InjectedStatement.java:96) at org.jukito.InjectedAfterStatements.evaluate(InjectedAfterStatements.java:58) at org.jukito.jukitoRunner.run(JukitoRunner.java:197)
我无法从中提取很多有用的信息。 看起来好像错误抱怨
verify(bar).deinit()
可能最后没有.deinit()
,我可以删除该部分并得到相同的错误。 错误消息中提供的示例特别令人沮丧,因为它看起来几乎与我使用verify
相同。细节
这是我的
BarImpl.java
public class BarImpl implements Bar { private final Qux qux; private final Quux quux; @Inject public BarImpl(final Qux qux, final Quux quux) { this.qux = qux; this.quux = quux; } @Override private final void init(Baz baz) { quux.init(this); qux.init(); } @Override public final void deinit() { qux.deinit(); //line XX } }
我还不清楚
qux.deinit()
在这里是如何导致失败的。 这是我的FooImpl.java
:class FooImpl implements Foo { private final Bar bar; @Inject public FooImpl(final Bar bar) { this.bar = bar; } @Override public void init(Baz baz) { bar.init(baz); } @Override public void deinit() { bar.deinit(); } }
题
导致UnfinishedVerificationException的原因是什么?如何解决?
我是Mockito newb所以我很可能错过了一些基本的东西。 如果我能提供更多信息,请告诉我。 很抱歉,如果已经回答了这个问题,我在这里误解了答案。
Introduction
I'm attempting to make a test which verifies (using Mockito v1.9.5's
verify
) that a method with signaturedeinit()
in an interfaceBar
is called after execution of a pass-throughFoo.deinit()
, and I'm hitting an error I really don't understand.Here's the
FooTest.java
which I'm attempting to run:@RunWith(JukitoRunner.class) public class FooTest { @Inject private Foo foo; @Inject private Bar bar; public static class TestModule extends JukitoModule { @Override protected void configureTest() { bind(Foo.class).to(FooImpl.class); bind(Bar.class).to(BarImpl.class); bindSpy(BarImpl.class); } } @Test public void testDeinit() { foo.init(mock(Baz.class)); foo.deinit(); verify(bar).deinit(); } @After public void validate() { validateMockitoUsage(); //line YY } }
When running this,
testDeinit()
fails with the following error:org.mockito.exceptions.misusing.UnfinishedVerificationException: Missing method call for verify(mock) here: -> at redacted.impl.BarImpl.deinit(BarImpl.java:XX) Example of correct verification: verify(mock).doSomething() Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods. Those methods *cannot* be stubbed/verified. at redacted.impl.FooTest.validate(FooTest.java:YY) at org.jukito.InjectedStatement.evaluate(InjectedStatement.java:96) at org.jukito.InjectedAfterStatements.evaluate(InjectedAfterStatements.java:58) at org.jukito.jukitoRunner.run(JukitoRunner.java:197)
Which I haven't been able to extract much useful information from. It seems almost as if the error complains that
verify(bar).deinit()
might as well not have a.deinit()
off the end, and I can remove that portion and get an identical error. The example provided in the error message is especially frustrating, as it appears almost identical to my use ofverify
.Details
Here's my
BarImpl.java
public class BarImpl implements Bar { private final Qux qux; private final Quux quux; @Inject public BarImpl(final Qux qux, final Quux quux) { this.qux = qux; this.quux = quux; } @Override private final void init(Baz baz) { quux.init(this); qux.init(); } @Override public final void deinit() { qux.deinit(); //line XX } }
I'm still unclear how the
qux.deinit()
causes failure here. Here's myFooImpl.java
:class FooImpl implements Foo { private final Bar bar; @Inject public FooImpl(final Bar bar) { this.bar = bar; } @Override public void init(Baz baz) { bar.init(baz); } @Override public void deinit() { bar.deinit(); } }
Question
What's causing the UnfinishedVerificationException and how can it be fixed?
I'm a Mockito newb so it's very likely I've missed something fundamental. Please let me know if there's more information I can provide. Sorry if this has been answered already and I've misunderstood answers here on SO.
原文:https://stackoverflow.com/questions/40350009
最满意答案
我的建议是使用JSON切换到更结构化的comm方式。 您可以定义自定义数据名称和类型,并轻松覆盖它们。 看一看:
https://github.com/bblanchon/ArduinoJson
这里是HTTPClient示例中的一些JSON示例:
DynamicJsonBuffer jsonBuffer(BUFFER_SIZE); JsonObject& root = jsonBuffer.parseObject(client); if (!root.success()) { Serial.println("JSON parsing failed!"); return false; } // Here were copy the strings we're interested in strcpy(userData->name, root["name"]); strcpy(userData->company, root["company"]["name"]);
My suggestion is to use JSON to switch to more structured way of comm. You can define custom data names and types and easily cover them. Take a look it at :
https://github.com/bblanchon/ArduinoJson
Here some JSON example from the HTTPClient example :
DynamicJsonBuffer jsonBuffer(BUFFER_SIZE); JsonObject& root = jsonBuffer.parseObject(client); if (!root.success()) { Serial.println("JSON parsing failed!"); return false; } // Here were copy the strings we're interested in strcpy(userData->name, root["name"]); strcpy(userData->company, root["company"]["name"]);
相关问答
更多-
所以,这里的问题都是时间问题。 您知道软件序列的缓冲区大小有限制(对于任何硬件UART也是如此),这是256字节,波特率为9600位/秒。 由于有一个起始位,8个数据位和一个停止位(假设您在这里使用9600 8N1,因为它是最常见的),您将每隔(1/9600)* 10秒或1.04接收一个数据字节毫秒。 因此,要接收256个字节,它应该需要大约266毫秒。 这意味着在266毫秒之后,您的缓冲区将完全填满,之后您收到的任何内容都将开始删除以前接收的数据。 而且存在问题的关键 - 您正在向ESP发送命令以从服务器 ...
-
编译Arduino时出错(Error compiling Arduino)[2023-05-24]
尝试安装Arduino SAMD板(32位ARM Cortex-M0 +)板(使用“工具” - >“板” - >“板卡管理器”菜单。只需在搜索栏中搜索“samd”,选择最新版本和安装) Try to install Arduino SAMD Boards (32-bits ARM Cortex-M0+) board (using "Tools" -> "Board" -> "Boards Manager" menu. Just search for "samd" in the search bar, cho ... -
我已经完成了......更改网址: https://taub-prayer-ramym.c9.io/girls I HAVE SUCCEDED.. CHANGE URL TO: https://taub-prayer-ramym.c9.io/girls
-
arduino ide没有开始(arduino ide does not start)[2019-11-29]
听起来你正在尝试运行在Java 1.7上为Java 1.8编译的IDE版本。 将java升级到1.8应该修复它。 Sounds like you are trying to run a version of the IDE that has been compiled for Java 1.8 on Java 1.7. Upgrading java to 1.8 ought to fix it. -
它在很大程度上取决于客户(即消费者)哪些字段是必需的,哪些是强制性的。 唯一一个始终需要的是“HTTP / 1.1 200 OK”。 当然,如果您没有发送OK消息,则需要替换该状态代码。 It largely depends on the client (i.e. consumer) which fields are required and which are mandatory. The only one that is always required is "HTTP/1.1 200 OK". Of ...
-
基本的伪代码大纲是这样的: int PWM; int minute_ctr; loop() { if (minute_ctr > 1000) { minute_ctr = 0; check HTML page for 1/0 } if (page == 1) PWM++; set PWM for LED (analogWrite) change direction when PWM = 0 or 255 else ...
-
如何使用Esp8266-arduino发送加密的发布请求?(How to send an encrypted post request using Esp8266-arduino?)[2023-06-04]
ESP8266绝对可以处理SSL。 事实上,Arduino存储库包含一个SSL客户端,作为其库的一部分。 以下是显示SSL执行基本HTTP请求的示例: https : //github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino The ESP8266 absolutely can handle SSL. In fact, the Arduino repository ... -
使用Arduino作为FTDI程序员编程ESP8266(ESP-12)(Using Arduino as FTDI programmer to program ESP8266 (ESP-12))[2023-09-14]
所以我提出的解决方案并不理想。 使用5V < - > 3.3V逻辑电平转换器会产生某种错误。 我的解决方案是将arduino上的TX / RX引脚直接插入ESP-12上的RX / TX引脚。 ESP-12上的RX / TX引脚不能正式支持5V逻辑,但在我看来它们似乎也是这样。 您自己承担使用5V逻辑的风险 。 我目前正在使用Arduino IDE 1.6.5的设置可以在下面的示意图中看到(尽管适用于ESP-12,而不是原理图中的ESP-1)。 要允许对ESP-12进行编程,必须先按SW1并按住SW2按住它。 ... -
使用以太网模块时,可能将Arduino配置为服务器。 Arduino必须通过以太网模块进行监听才能响应传入的连接。 那么,如果你已经开始使用GSM模块,你需要做同样的事情。 您需要将其设置为服务器。 不幸的是,这是不可能的。 网络服务提供商不允许入站连接,因为单个公共IP地址被许多订户共享。 无论发生什么,都清楚的是,另一端的设备不能启动连接; GSM模块必须始终先走。 根据您的意图,您应该让Arduino + SIM900定期使用状态更新ping服务器,或者使用keep-alive HTTP 1.1标头连 ...
-
我的建议是使用JSON切换到更结构化的comm方式。 您可以定义自定义数据名称和类型,并轻松覆盖它们。 看一看: https://github.com/bblanchon/ArduinoJson 这里是HTTPClient示例中的一些JSON示例: DynamicJsonBuffer jsonBuffer(BUFFER_SIZE); JsonObject& root = jsonBuffer.parseObject(client); if (!root.success()) { Se ...