gpt4 book ai didi

java - 'SRPy' 在 Mockito 文档中代表什么

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:55 26 4
gpt4 key购买 nike

来自 http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html

As usual you are going to read the partial mock warning: Object oriented programming is more less tackling complexity by dividing the complexity into separate, specific, SRPy objects. How does partial mock fit into this paradigm? Well, it just doesn't... Partial mock usually means that the complexity has been moved to a different method on the same object. In most cases, this is not the way you want to design your application.

最佳答案

根据 Mockito 文档 for Spy ,

Spying on real objects is often associated with "partial mocking" concept. However, Mockito spies are not partial mocks. Mockito spy is meant to help testing other classes - not the spy itself. Therefore spy will not help if you intend to verify if method calls other method on the same object. In this case I suggest being OO/SRPy (for example you might extract new class/interface...)

OO指的是面向对象,SRP指的是Single responsibility principle。这是一种设计模式,规定类应该有一个且只有一个责任,在这种情况下,您倾向于编写不需要测试是否调用内部方法的代码。

http://en.wikipedia.org/wiki/Single_responsibility_principle

关于java - 'SRPy' 在 Mockito 文档中代表什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057754/

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