Concept of Mocking

Mocking is the process of just focusing on the code that needs to be tested not at all whats going on with the behavior of the outside dependencies. Therefore we sort of use a cheat code here, we use replacement objects ro kind of replicate the behavior of the real external more complex code. Immediately, this loophole has caught my attention as this seems like a great work around and will make my time creating test code much more efficient. And were all about efficiency when it comes to coding.

Back to the matter at hand, we should go over the three types of replacement objects. This objects include, Fakes, Mocks and Stubs. As a lot of information is rolled out onto us using these concepts i find it important to take a little time to really simplify what each of these terms mean.

A Fake is an object that has actual working code but returns a predicatable result, but “will not implement the actual production logic” ( In addition, a Stub is an object that will test specific inputs for some rather specfic results. The problem with a Stub is just that though, its too specific so once your begin to change inputs, the stub will begin throwing exceptions. Then lastly is where the much more sophisticated Mock comes into play. A Mock is similair to a Stub but also able to control how many times methods are called, in what order and with what set of data as well.

To conclude here, this overall concept of mocking using replacement objects, are used not to subsitute unit testing, but instead they isolate the dependencies, making test code more focused and efficient. There it is, efficiency, the holy grail of words when it comes to coding and that is the number one reason Mocking is used.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: