This is my final post, at least for the foreseeable future, and it is based on Martin Fowler’s article Mocks Aren’t Stubs. In unit testing, the ability to test a unit is sometimes dependent on other units, which may not have been created yet. Mocks can be used in this case. Fowler point out that “the vocabulary for talking about this soon gets messy – all sorts of words are used: stub, mock, fake, dummy.” So for clarification, here is a quick vocabulary lesson:
- Test Double: A generic term for any kind of pretend object used in place of a real object for testing purposes
- Dummy: An object that is passed around but never actually used. Usually used to fill parameter lists.
- Fake: An object actually have working implementations, but usually take some shortcut which makes it not suitable for production
- Stub: Something that provides a canned answer to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test. A stub may also record information about calls
- Mock: An object pre-programmed with expectations which form a specification of the calls it is expected to receive
From the blog cs443 – TayNock's Blog by taynock and used with permission of the author. All other rights reserved by the author.