我正在使用 ScalaMock 和 ScalaTest 来组合一些单元测试。我想使用 ScalaMock 的期望语法来确认我正在处理的服务将可接受的 Json 传递给模拟资源。在这种情况下,可接受意味着某些内部字段可能不同,因此我编写了一个自定义函数来确定我关心的字段是否匹配。这样做的问题是,当期望没有实现时,它会产生相对无用的日志记录。预期设置如下:
(mockedResource.doAThing(_: Json)(_: SomeImplicitThing))
.expects(
where(
jsonSimilarAndImplicitEqual(
expectedJson,
anInstanceOfImplicitThing
)(_, _)
)
)
产生以下登录失败:
- should forward acceptable Json to the mockedResource
Unsatisfied expectation:
Expected:
[info] inAnyOrder {
[info] <mock-1> MockedResource.doAThing<function1> once (never called - UNSATISFIED)
[info] }
我希望能够提供一些自定义日志记录功能来描述为什么jsonSimilarAndImplicitEqual
在合理的地方评估为假。我希望一个inAnyOrderWithLogging
块就足够了,但事实证明我什至不能使用这个构造,因为 AsyncMockFactory 不支持它。