What is a “Stub”?

前端 未结 6 2079

So, carrying on with my new years resolution to get more in to TDD, I am now starting to work more with Rhino Mocks.

One thing I am keen to do is to make sure I reall

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 06:04

    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.

提交回复
热议问题