gpt4 book ai didi

java - 对 MockUp 与 Expectations 的优点感到困惑

转载 作者:行者123 更新时间:2023-12-02 11:34:44 26 4
gpt4 key购买 nike

我刚刚开始使用 JMockit,并且对使用 MockUp 进行“伪造”与使用 Expectations 来模拟对象的优势感到困惑。

根据我阅读的文档,类的 MockUp 允许我用自己的实现覆盖方法。然而,我发现我可以在期望 block 中做类似的事情。

那么 MockUp 与 Expectations 相比有何优势?根据JMockit docs ,

Fakes are different from the mocking API in that, rather than specifying in a test the invocations we expect a dependency will receive when used by code under test, we modify the implementation of the dependency so that it suits the needs of the test.

这不就是语义吗?从功能上来说,使用 Expectations() block 而不是使用 MockUp<> 是否无法实现相同的功能?

最佳答案

您的问题是:使用 Expectations 和 Mockup API 有什么区别?

我对此很陌生,但对我来说,这主要是做同一件事的两种不同方式。您选择哪个只是品味以及您想要如何测试代码的问题。在 Mockup API 中,您可以在一个语句 block 中指定模拟,而在 Expectations 中,您将使用 Expectations block 和 Verifications block 。除此之外,他们看起来也和我很相似。

关于java - 对 MockUp 与 Expectations 的优点感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32815486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com