Monday, April 09, 2007

Google Stubs

The Google Testing Blog points us to stubs; one of the things I never get right with unit tests.

To summarize:
  • 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.
... which I rarely make use of.

Instead of actually connecting to a database and reading information, a stub just returns the results you'd expect, or simulates a failure; and so forth.

No comments: