Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
The Language of Mocks (or is that Test Doubles)

Ian Cooper brought up an interesting point on the altdotnet mailing list recently, around the language used to describe Mocks, or more accurately his preference for the term Test Double over my use of the generic term Mock.

In most areas of development I can often be considered a language perfectionist, for example calling something a Unit Test when it is *clearly* an Integration Test drives me nuts - but when it comes to Mocks, Stubs, Fakes, Spys, or the rather more generic Test Doubles ... I just can't get passionate about the language.

This all started a while ago, when people started using the term mock, but really it wasn't a mock - or more often they used the term mock when referring to what many mock frameworks call a Strict Mock, just one type of mock.

Martin Fowler long ago posted on a clarification of the terminology around mocking, and xUnitPatterns has a fuller description. The distinction that Gerard Meszaros introduced was to use the term Test Double to describe all of these things we use to help us test our code. Fakes, Spys, Mocks, Dummys ... all just a type of Test Double.

Now language is important. Very important. As Ian pointed out in his email, most arguments centre around a misunderstanding of the terminology involved - I'm sure the world would be a nicer place if language was universal and could not be interpreted differently by different people, but then it would be a linguistically poorer place for it too.

In development, language is something that is vital to good communication of what are often very complex technical concepts. We evolved the languages of patterns and principles to allow us to avoid confusion and misunderstandings, and most areas of development have their own specific language terminology.

But, with this one area of testing I have a problem with the terminology, because the term that I hear from developers on a daily basis is "mocking", not "test doubles". And when terminology enters the common language, it is very hard to replace it with a new term just because you prefer it. I'm sure that Test Double describes the concept better, and I'm sure that it is important to have some distinction between Mocks and Fakes, but in my experience, that is not how developers refer to these things.

It is much easier to say "we can mock this out" than it is to say "we can create a test double here", the first is just more natural in the English language. So the term "mock" has become almost a defacto term for what Martin Fowler et al refer to as a Test Double, whilst also being a Mock with a capital M for describing the Mock that most mock frameworks create.

So, much as I might like to be a language perfectionist on this one, I tend to just use the term mock, and leave the decision as to whether it is a Mock, Fake, Stub or Whatever to the point I actually code it. So far nobody has misconstrued Mock to mean "you must use a mocking framework", or at least not anyone to whom the concepts of mocking are not entirely new anyway, in which case much more clarification is needed in any case.




Posted 06-11-2008 10:25 AM by Jak Charlton
Filed under: , ,



Derik Whittaker wrote re: The Language of Mocks (or is that Test Doubles)
on 06-11-2008 6:52 AM

I know that when i am giving a session on Mocking I am very careful to try to explain the differences between the various terms and how they can be/should be used.

Often times the simple mistake of not understanding the terms/language can trip people up.

Dew Drop – June 11, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop – June 11, 2008 | Alvin Ashcraft's Morning Dew
on 06-11-2008 8:37 AM

Pingback from  Dew Drop – June 11, 2008 | Alvin Ashcraft's Morning Dew

Reflective Perspective - Chris Alcock » The Morning Brew #113 wrote Reflective Perspective - Chris Alcock » The Morning Brew #113
on 06-12-2008 3:17 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #113

WSDAC#7 - SCRUM in 90 minutes - Service Endpoint wrote WSDAC#7 - SCRUM in 90 minutes - Service Endpoint
on 06-17-2008 12:06 AM

Pingback from  WSDAC#7 - SCRUM in 90 minutes - Service Endpoint

trans wrote re: The Language of Mocks (or is that Test Doubles)
on 10-21-2008 7:15 AM

I totally agree. the term 'mock' does nothing to convey the idea of embedded expectations. if we use terms that more readily convey our intended ideas in the first place, we would not need to waste so much time explaining what we mean. A term like 'appraiser' would be a much better way to convey the idea of a "strict Mock".

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)