Fake objects vs Mock objects

There are two concepts in TDD: fake objects and the layout of objects. These two concepts are used if the class you want to test interacts with other classes or objects or databases ...

My question is: what is the difference between the two? and when can i use each of them?

Edit: I found this answer: What is the difference between falsification, ridicule and stubbing?

But I'm still confused by the difference between the two: both of them create a component implementation, with an easy implementation for Fake. But what do they mean by "easy implementation" of the "label" in the case of fake? And what is the difference between how the Mock object works and the real object?

+5
source share
1 answer

A fake implementation for a DataSet , for example, will simply return a static dataset. The layout would be pretty much a complete implementation that could generate different data sets depending on the input. If you mocked your data level, you could execute your command objects against the layout, and it would be strong enough to return data using a β€œvalid” statement or throw exceptions with an invalid statement. All without actually connecting to a database or file.

As for the differences between mock and real, usually when you mock a class, you should create a factory object that returns the real object by default, but when you write your tests, you can tell it to return a specific class layout. The mock class implements the same interfaces as the real object, or you use a wrapper class that mimics the base class but allows dependency injection for critical parts to generate data without external calls.

+1
source

Source: https://habr.com/ru/post/1238256/


All Articles