Wednesday, April 04, 2007

Note to self: Always learn and keep looking for the "better way"

Google Testing Blog: TotT: Stubs Speed up Your Unit Tests: "By substituting custom objects for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.

A variety of different terms are used to refer to these “custom objects”. In an effort to clarify the vocabulary, Gerard Meszaros provides the following definitions:

* Test Double is a generic term for any test object that replaces a production object.
* Dummy objects are passed around but not actually used. They are usually fillers for parameter lists.
* Fakes have working implementations, but take some shortcut (e.g., InMemoryDatabase).
* Stubs provide canned answers to calls made during a test.
* Mocks have expectations which form a specification of the calls they do and do not receive."

No comments: