A method stub or simply stub
in
software development
Software development is the process of conceiving, specifying, designing, programming, documenting, testing, and bug fixing involved in creating and maintaining applications, frameworks, or other software components. Software development invol ...
is a piece of code used to stand in for some other programming functionality. A stub may
simulate
A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of Conceptual model, models; the model represents the key characteristics or behaviors of the selected system or proc ...
the behavior of existing code (such as a
procedure
Procedure may refer to:
* Medical procedure
* Instructions or recipes, a set of commands that show how to achieve some result, such as to prepare or make something
* Procedure (business), specifying parts of a business process
* Standard operat ...
on a remote machine; such methods are often called mocks) 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 examination (exam or evaluation) or test is an educational assessment intended to measure a test-taker's knowledge, skill, aptitude, physical fitness, or classification in many other topics (e.g., beliefs). A test may be administered verba ...
.
An example of a stub in
pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
might be as follows:
temperature = ThermometerRead(Outside)
if temperature > 40 then
print "It is hot!"
end if
function ThermometerRead(Source insideOrOutside)
return 28
end function
The above pseudocode utilises the function , which returns a temperature. While would be intended to read some hardware device, this function currently does not contain the necessary code. So does not, in essence,
simulate
A simulation is the imitation of the operation of a real-world process or system over time. Simulations require the use of Conceptual model, models; the model represents the key characteristics or behaviors of the selected system or proc ...
any process, yet it ''does'' return a legal value, allowing the main program to be at least partially tested. Although it accepts the
parameter of type , which determines whether inside or outside temperature is needed, it does not use the actual value passed (
argument
An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
) by the caller in its logic.
A stub 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
RMI may refer to:
Science and technology
* Radio-magnetic indicator, an instrument used in aircraft navigation
* Repetitive motion injury, an injury to the musculoskeletal and nervous systems
* Richtmyer–Meshkov instability, an instability occu ...
nomenclature, a stub on the client-side communicates with a
skeleton
A skeleton is the structural frame that supports the body of an animal. There are several types of skeletons, including the exoskeleton, which is the stable outer shell of an organism, the endoskeleton, which forms the support structure inside ...
on the server-side.
In the context of
DOS and
Windows, the term ''stub'' is also used in a fashion like
shim
Shim may refer to:
* Shim (spacer), a thin and often tapered or wedged piece of material
** CPU shim, a spacer for a computer heat sink
** Shim (fencing), a device used in the sport fencing
** Shim (lock pick), a tool used to bypass padlocks
* Sh ...
to describe the small areas of interface code left in
conventional memory by
self-relocating
In computer programming, a self-relocating program is a program that relocates its own address-dependent instructions and data when run, and is therefore capable of being loaded into memory at any address. In many cases, self-relocating code is a ...
resident drivers which move most of themselves into
upper memory, the
high memory area
In DOS memory management, the high memory area (HMA) is the RAM area consisting of the first 65520 bytes above the one megabyte in an IBM AT or compatible computer.
In real mode, the segmentation architecture of the Intel 8086 and subsequen ...
,
expanded or
extended memory as well as similar stubs to allow the relocated code to communicate with
real-mode DOS in conjunction with
DOS extender
A DOS extender is a computer software program running under DOS that enables software to run in a protected mode environment even though the host operating system is only capable of operating in real mode.
DOS extenders were initially developed ...
s (like
DPMI,
DPMS,
CLOAKING or
NIOS).
The small pieces of dummy code branched into—so as to allow a graceful exit when invoking a
fat binary in the wrong environment—are also called (code) stubs.
See also
*
Abstract method
*
Mock object
*
Dummy code
*
Test stub
In advanced polymorphism computer science, test stubs are programs that simulate the behaviours of software components (or modules) that a module undergoing tests depends on. Test stubs provide canned answers to calls made during the test, usuall ...
*
Glue code
*
Shim (computing)
*
DOS stub
The New Executable (abbreviated NE or NewEXE) is a 16-bit .exe file format, a successor to the DOS MZ executable format. It was used in Windows 1.0–3.x, Windows 9x, multitasking MS-DOS 4.0, OS/2 1.x, and the OS/2 subset of Windows NT up to ver ...
References
{{reflist
External links
A Stub Generation System For C++(PDF)
Review and comparison of stub & mock frameworks for Java
Unit testing
Computer programming folklore
Software development