Unit Testing in Java: How Tests Drive the Code (The Morgan Kaufmann Series in Software Engineering and Programming)

6.12 More Typical Mock Objects

The use of mock objects is convenient in various places in our code. The mock streams described in the previous section are just as typical as the examples we will see later in the realm of databases (see Chapter 9) and Web applications (see Chapter 12). Here are a few additional ideas:

This type of testing is very sensitive to minor modifications of our CUT's implementation, therefore we recommend it exclusively for cases where the exact sequence is part of the specification. This is often the case with frameworks, where abstract framework superclasses guarantee the invocation sequence of abstract methods. [4]

[4]This corresponds to the Template Method design pattern [Gamma95].

Категории