简体   繁体   English

Mockito.verify 的 AssertJ 解决方案

[英]AssertJ solution for Mockito.verify

Browsing through the API of AssertJ, I didn't seem to come across anything that covers the behaviour of that of Mockito.verify.浏览 AssertJ 的 API,我似乎没有遇到任何涵盖 Mockito.verify 行为的内容。 Right now my assertions are all using the AssertJ fluent API, and then there's the Mockito.verify which is kind of breaking the flow of the assertions.现在我的断言都使用 AssertJ fluent API,然后是 Mockito.verify,它有点打破断言的流程。

Is there a similar way to verify that a method is not called, called exactly once, etc. in AssertJ that I missed?是否有类似的方法来验证我错过的 AssertJ 中的方法未被调用、仅调用一次等?

不,AssertJ 只是一个断言库,而不是一个模拟库,未来没有提供模拟的计划,因为 Mockito 已经在这方面做得很好。

I tried something like this:我试过这样的事情:

SoftAssertions.assertSoftly(softly -> {
        softly.assertThat(someValue).isNull();
        softly.assertThatCode(() -> verify(mockedInstance).someCall(eq("argument")))
              .doesNotThrowAnyException();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM