Dummy,Stub,Fake,Mock简介

转载自:https://www.cnblogs.com/2018/archive/2012/09/18/2681117.html

Dummy

An object that is passed around but never used. Typically used to fulfill the parameter list of

a method.

Stub

An object that always returns the same canned response. May also hold some dummy state.

Fake

An actual working implementation (not of production quality or configuration) that can replace the real implementation.

Mock

An object that represents a series of expectations and provides canned responses.

1、Dummy
A dummy object is the easiest of the four test double types to use. Remember, it’s designed to help fill parameter lists or fulfill some mandatory field requirements where you know the object will never get used. In many cases, you can even pass in an empty or null object.

 @Test

  public void tenPercentDiscount() {

    String dummyName = "Riley";        

    Ticket ticket = new Ticket(dummyName,  new BigDecimal("10"));

    assertEquals(new BigDecimal("9.0"), ticket.getDiscountPrice());

  }

2、Stub object
You typically use a stub object when you want to replace a real implementation with an

object that will return the same response every time. Let’s return to our theater ticket

pricing example to see this in action.

 @Test

  public void tenPercentDiscount() {

Price price = new StubPrice(); 

 Ticket ticket = new Ticket(price);           

    assertEquals(9.0,

                 ticket.getDiscountPrice().doubleValue(),

                0.0001);       

  }

public class StubPrice implements Price {

  @Override

  public BigDecimal getInitialPrice() {

    return new BigDecimal("10");         

  }

}

3、Fake object
A fake object can be seen as an enhanced stub that almost does the same work as your production code, but that takes a few shortcuts in order to fulfill your testing require -ments. Fakes are especially useful when you’d like your code to run against something that’s very close to the real third-party subsystem or dependency that you’ll use in the live implementation

Most well-grounded Java developers will sooner or later have to write code that interacts with a database, typically performing CRUD operations on Java objects. Prov-ing that your Data Access Object ( DAO) code works before running it against the pro-duction database is often left until the system integration test phase, or it isn’t checked at all! It would be of great benefit if you could check that the DAO code works during your unit test or integration test phase, giving you that all important, fast feedback.

A fake object could be used in this case—one that represents the database you’re interacting with. But writing your own fake object representing a database would be quite difficult! Luckily, over recent years, in-memory databases have become small enough, lightweight enough, and feature-rich enough to act as a fake object for you.

HSQLDB (www.hsqldb.org) is a popular in-memory database used for this purpose.

4、Mock object
Mock objects are related to the stub test doubles that you’ve already met, but stub objects are usually pretty dumb beasts. For example, stubs typically fake out methods so that they always give the same result when you call them. This doesn’t provide any way to model state-dependent behavior.

Mockito (available from http://mockito.org/

@Test

public void tenPercentDiscount() {

Price price = mock(Price.class);          

when(price.getInitialPrice()).

     ➥ thenReturn(new BigDecimal("10"));           

Ticket ticket = new Ticket(price, new BigDecimal("0.9"));

assertEquals(9.0, ticket.getDiscountPrice().doubleValue(), 0.000001);

verify(price).getInitialPrice();

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dummy metal是为了解决芯片制造过程中的一些问题而添加的虚拟金属层。根据引用\[1\],dummy metal可以用于增加金属密度,以防止金属密度不足的情况。此外,dummy metal还可以用于考虑光的反射和衍射,确保关键图形的尺寸不受曝光的影响。 根据引用\[2\],在使用PVS生成dummy metal时,可以直接考虑dummy对时序的影响,并在innovus中修剪dummy以减少不必要的时序调整。生成的GDS文件也包含dummy metal,可以直接用于后续的StarRC使用。 引用\[3\]提到了MOS dummy的应用。在MOS两侧增加dummy poly可以避免长度受到影响。对于NMOS,先加P型guard ring连接VSS,然后加N型guard ring连接VDD。对于PMOS,先加N型连接VDD,然后加P型连接VSS。拆分MOS时,应为偶数根,并将Source端与周围的guard ring就近连接。 综上所述,dummy metal是为了解决芯片制造过程中的问题而添加的虚拟金属层,可以用于增加金属密度、考虑光的反射和衍射,并对时序结果产生影响时进行修剪。在MOS中,dummy metal的应用可以避免长度受到影响。 #### 引用[.reference_title] - *1* *3* [CMOS 器件版图 DUMMY 图形](https://blog.csdn.net/weixin_45881793/article/details/127023332)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [使用PVS生成MetalDummy的实现方法](https://blog.csdn.net/kobayashiyou/article/details/119928600)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值