我正在尝试验证记录器是否被调用。问题是它返回 void,因此建议我使用 spy 而不是 stub。不幸的是,间谍的行为很古怪(不工作)。理想情况下,我还想删除“味精”并使用匹配器。
代码如下。我也尝试过https://stackoverflow.com/a/24150445/555493给出的方法,但我仍然遇到类似的错误。
//setup spy
val logger = spy(new Logger)
logger.debug(msg)
//call code
//verify
there was one(logger).debug(msg)
我收到此错误:
The mock was not called as expected:
Argument(s) are different! Wanted:
logger.debug(
($anonfun$apply$mcV$sp$1) <function0>
);
-> at HttpHealthCheckSpec$$anonfun$35$$anon$11$$anonfun$11.apply$mcV$sp(HttpHealthCheckSpec.scala:176)
Actual invocation has different arguments:
logger.debug(
($anonfun$setupMock$1) <function0>
);
-> at HttpHealthCheckSpec.setupMock(HttpHealthCheckSpec.scala:58)