3

In his talk, Ian Cooper (at 33:30), mentioned the imposter design pattern. Searching the net, I found that it is introduced in the Test Driven Development : by example, but I couldn't find any more details.

  • what exactly is the imposter design pattern?
  • how to implement it in c++?
Charles
  • 50,943
  • 13
  • 104
  • 142
BЈовић
  • 62,405
  • 41
  • 173
  • 273
  • I've not heard of Ian or the pattern (every man and his dog gropes for a name for anything they suspect might be a pattern these days, making one up if they get bored of searching), but from the brief description in the page you link it sounds much like [mocking](http://en.wikipedia.org/wiki/Mock_object) – Tony Delroy Mar 28 '14 at 10:07
  • @TonyD Yes, it is about mocking, but I would like to see details how to implement it. I know you can create mock objects using factory, but so far I never heard of the imposter design pattern. – BЈовић Mar 28 '14 at 10:12
  • You can create mock objects in lots of ways - just depends if the code you want to test them with uses dependency injection (CT or RT), setter function, factories or whatever other approach to choosing which object to use. Anyway, seems we're waiting on Ian or someone else to say if/how "imposter" differs from mocking. – Tony Delroy Mar 28 '14 at 10:36

1 Answers1

7

Imposter is also known as Test Double.

When we are writing a test in which we cannot (or choose not to) use a real depended-on component (DOC), we can replace it with a Test Double. The Test Double doesn’t have to behave exactly like the real DOC; it merely has to provide the same API as the real DOC so that the SUT thinks it is the real one!

Implementation depends on the variation:

Sketch types of test doubles
(source: xunitpatterns.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111