A "stub" is an implementation of an interface that exists to provide data/a response of some sort. For example:
- a DataSet
- list of Users
- an Xml File
Normally this would be provided by another service (be it Web Service, another application, a database) but in order to improve the testability of the code, the results are "faked".
A major benefit of this is that it allows assertions to be made in unit tests based on the data expected. If errors arise due to data errors, then tests can easily be added, a new stub created (replicating the data error) and code produced to correct the error.
Stubs differ to Mocks in that they are used to represent and test the state of an object, whereas a Mock tests its interaction.