what is stub?

小知识点,我google了一下,找了一些认为比较满意的答案贴过来。供君参考。



实际上如果你知道它是 substitute的缩写就可以了

A stub is a small program routine that substitutes for a longer program, possibly to be loaded later or that is located remotely. For example, a program that uses Remote Procedure Calls ( RPC ) is compiled with stubs that substitute for the program that provides a requested procedure. The stub accepts the request and then forwards it (through another program) to the remote procedure. When that procedure has completed its service, it returns the results or other status to the stub which passes it back to the program that made the request.

A routine that doesn‘t actually do anything other than declare itself and the parameters it accepts. Stubs are used commonly as placeholders for routines that still need to be developed. The stub contains just enough code to allow it to be compiled and linked with the rest of the program.

A stub is a controllable replacement for an existing dependency (or collaborator) in the system. By using a stub, you can test your code without dealing with the dependency directly.

这里的dependency可能是指,函数或者类等等:

Anything that the code uses. It might help to understand if you re-read and replace "dependency" with "class" or "function" or whatever (depends on your background).

A stub, in this context, means a mock implementation.

That is, a simple, fake implementation that conforms to the interface and is to be used for testing.

---------------------------------------------------------------------------------

更加专业一点儿的解释:

A stub, in the context of distributed computing, is a piece of code that is used to convert parameters during a remote procedure call (RPC). An RPC allows a client computer to remotely call procedures on a server computer. The parameters used in a function call have to be converted because the client and server computers use different address spaces. Stubs perform this conversion so that the remote server computer perceives the RPC as a local function call.

翻译做中转或者替代,多为机器自动产生。

Stub libraries are generally installed on the client and server. Client stubs convert parameters used in function calls and reconvert the result obtained from the server after function execution. Server stubs, on the other hand, reconvert parameters passed by clients and convert results back after function execution.

Stubs are generated either manually or automatically. In a manual generation, a remote procedure call implementer provides translation functions, from which a user constructs stubs. They handle complex parameter types. Automatic stub generation is commonly used to generate stubs. They use integration description language to define client and server interfaces.

---------------------------------------------------------------------------------------------------------------------

更经典的总结:

https://en.wikipedia.org/wiki/Method_stub

A method stub or simply stub in software development is a piece of code used to stand in for some other programming functionality. A stub may simulate the behavior of existing code (such as a procedure on a remote machine) or be a temporary substitute for yet-to-be-developed code. Stubs are therefore most useful in porting, distributed computing as well as general software development and testing.

An example of a stub in pseudocode might be as follows:

   BEGIN
       Temperature = ThermometerRead(Outside)
       IF Temperature > 40 THEN
            PRINT "It‘s HOT!"
       END IF
   END
   BEGIN ThermometerRead(Source insideOrOutside)
        RETURN 28
   END ThermometerRead

The above pseudocode utilises the function ThermometerRead, which returns a temperature. While ThermometerRead would be intended to read some hardware device, this function currently does not contain the necessary code. So ThermometerRead does not, in essence, simulate any process, yet it does return a legal value, allowing the main program to be at least partially tested. Also note that although it accepts the parameter of type Source, which determines whether inside or outside temperature is needed, it does not use the actual value passed (argument insideOrOutside) by the caller in its logic.

A stub [1] is a routine that doesn‘t actually do anything other than declaring itself and the parameters it accepts and returning something that is usually the values expected in one of the "happy scenarios" for the caller. Stubs are used commonly as placeholders for implementation of a known interface, where the interface is finalized/known but the implementation is not yet known/finalized. The stub contains just enough code to allow it to be compiled and linked with the rest of the program. In RMI nomenclature, a stub communicates on the server-side with a skeleton.[2]



Android Binder这一块儿也有个Stub,如果你理解Binder的话,那么stub就很好理解了。

更通俗的理解是: “默认生成,有待实现

就这样,不贪多。

merlin

2015/10/22

时间: 2024-10-27 19:44:40

what is stub?的相关文章

使用Mockito进行单元测试【2】—— stub 和 高级特性[转]

一篇中介绍了Mockito的基本信息,现在接着介绍Mockito强大的stub功能 2. Mockito使用实例 5. 对连续的调用进行不同的返回 (iterator-style stubbing) 还记得在实例2中说道当我们连续两次为同一个方法使用stub的时候,他只会使用最新的一次.但是在某一个方法中我们确实有很多的调用怎么办呢?mockito当然想到这一点了: Java代码   when(mock.someMethod("some arg")) .thenThrow(new Ru

10个常见的Node.js面试题

如果你希望找一份有关Node.js的工作,但又不知道从哪里入手评测自己对Node.js的掌握程度. 本文就为你罗列了10个常见的Node.js面试题,分别考察了Node.js编程相关的几个主要方面. 在进入正文之前,需要提前声明两点: 这些问题只是Node.js知识体系的一个局部,并不能完全考察被面试者的实际开发能力. 对现实世界开发中遇到的问题,需要的是随机应变与团队合作,所以你可以尝试结对编程. Node.js面试题列表 什么是错误优先的回调函数? 如何避免回调地狱? 如何用Node来监听8

远程调用相关技术

相关术语: 中间件:中间件是一种独立的系统软件或服务程序,分布式应用软件借助这种软件在不同的技术之间共享资源.中间件位于客户机/ 服务器的操作系统之上,管理计算机资源和网络通讯.是连接两个独立应用程序或独立系统的软件.相连接的系统,即使它们具有不同的接口,但通过中间件相互之间仍能交换信息.执行中间件的一个关键途径是信息传递.通过中间件,应用程序可以工作于多平台或 OS 环境. 中间件(middleware)是基础软件的一大类,属于可复用软件的范畴.顾名思义,中间件处于操作系统软件与用户的应用软件

原!关于java 单元测试的一些总结

最近项目有在写java代码的单元测试,然后在思考一个问题,为什么要写单元测试??单元测试写了有什么用??百度了一圈,如下: 软件质量最简单.最有效的保证: 是目标代码最清晰.最有效的文档: 可以优化目标代码的设计: 是代码重构的保障: 是回归测试和持续集成的基石. 由于开发经验有限,可能说的不太对,但是是我目前的个人的观点,写单元测试,有时候确实可以发现bug,但是发现bug次数很少,而且目前都是项目开发完了,要上线了,公司有80%的覆盖率要求,所以都是后期上线之前补.目前而言,并没有在很认真地

Android系统移植与平台开发(七)- 初识HAL

1.      HAL的module与stub HAL(Hardware AbstractLayer)硬件抽象层是Google开发的Android系统里上层应用对底层硬件操作屏蔽一个软件层次,说白了,就是上层的应用不用关心底层硬件具体如何工作的,只要向上层提供一个统一的接口即可,这种设计思想广泛的存在于当前的软件架构设计里. 严格来讲,Android系统里完全可以没有HAL硬件抽象层,上层应用层可以通过API调用到底层硬件,但是Android自出现开始一直打着开源的旗号,而一些硬件厂商由于商业因

存根类(stub) 是什么意思?有什么作用?(转)

存根类是一个类,它实现了一个接口,但是实现后的每个方法都是空的. 它的作用是:如果一个接口有很多方法,如果要实现这个接口,就要实现所有的方法.但是一个类从业务来说,可能只需要其中一两个方法. 如果直接去实现这个接口,除了实现所需的方法,还要实现其他所有的无关方法.而如果通过继承存根类就实现接口,就免去了这种麻烦 这个在omco2.6版本中用户登录的session中的接口就有体现. 1 package com.utstar.omco.jnti.inc; 2 3 4 public interface

为什么V8引擎这么快?(转载)

转自:http://www.cnblogs.com/yumianhu/p/3707427.html 转载请注明出处:http://blog.csdn.net/horkychen Google研发的V8 JavaScript引擎性能优异.我们请熟悉内部程序实现的作者依源代码来看看V8是如何加速的. 作者:Community Engine公司研发部研发工程师Hajime Morita   Google的Chrome中的V8 JavaScript引擎,由于性能良好吸引了相当的注目.它是Google特别

hibernate session.get(class,serialid) 方法为空值的原因?

package hibernate.test; import hibernate.test.pojo.Person; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; impo

初识 PHPunit stub 模拟返回数据

这是这段时间以来结合 PHPunit 文档和大牛们的讲解,想记录下自己学习到的知识,未来参考补充,完善学到的东西 我们一般使用单测对公司业务里的代码进行测试,他会帮忙找到你的一个个小小的思考不够全面的地方.(虽然大牛说过开发可以先写单测再来写实现的代码,然而现在的我感觉离那个还是有好多距离来着) stub(桩件): “将对象替换为(可选地)返回配置好的返回值的测试替身的实践方法称为上桩(stubbing)”——这是官方文档给出的上桩解释 现在倒回来看我才理解,怎么说呢?举个梨子. ====前提