What is a “Stub”?

前端 未结 6 2106

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:08

    I faced the question recently and recognised that this comparison between Stub and Driver is really clear and helpful:

    Basically, stubs and drivers are routines that don’t actually do anything except declare themselves and the parameters they accept. The rest of the code can then take these parameters and use them as inputs.

    +---------+-------------------------------+-------------------------------+
    |         | Stub                          | Driver                        |
    +---------+-------------------------------+-------------------------------+
    | Type    | Dummy codes                   | Dummy codes                   |
    +---------+-------------------------------+-------------------------------+
    | Used in | Top Down Integration          | Bottom Up Integration         |
    +---------+-------------------------------+-------------------------------+
    | Purpose | To allow testing of the upper | To allow testing of the lower |
    |         | levels of the code, when the  | levels of the code, when the  |
    |         | lower levels of the code are  | upper levels of the code are  |
    |         | not yet developed.            | not yet developed.            |
    +---------+-------------------------------+-------------------------------+
    | Example | A and B are components.       | A and B are components.       |
    |         | A ---> B                      | A ---> B                      |
    |         |                               |                               |
    |         | A has been developed.         | A still needs to be developed.|
    |         | B still needs to be developed.| B has been developed.         |
    |         | Therefore, stub is used       | Therefore, driver is used     |
    |         | in place of B to imitate it.  | in place of A to imitate it   |
    |         |                               |                               |
    |         | A ---> Stub                   | Driver ---> B                 |
    +---------+-------------------------------+-------------------------------+
    

    From Difference between Stub and Driver

提交回复
热议问题