What Does Mocking Mean in Testing?
Asked by
CuriousCoder88
I'm trying to wrap my head around the term 'mocking' because it seems to have different meanings in various contexts. For instance, when we talk about 'mocking frameworks' versus 'mocking and stubbing,' there seems to be a lot of overlap. In unit testing, it often refers to using test doubles like mocks, stubs, and fakes. But I've also seen it used to describe just a mock test double. Can anyone clarify if mocking really does mean different things depending on the context?
Answers
Mocking is a broad concept that generally refers to substituting functionality that you control. You can achieve this with a mocking framework, or you can create your own mock class implementations if you prefer.
Reply to this answer
Google offers some of the best insights on this; they clarify definitions well. Generally speaking, the terms 'mock,' 'fake,' and 'stub' often get used interchangeably in casual discussions, which can lead to the confusion you're experiencing.
Reply to this answer
There isn't a universally accepted definition for these terms, so it can vary. I found a recent video that dives into this topic further if you're interested in exploring it more deeply: [YouTube Link](https://www.youtube.com/watch?v=RvKPOjlQKyM).
Reply to this answer
At the end of the day, the aim of mocking in different contexts is the same: to control certain code during a test. For example, you might want to mock a database interaction to handle both success and error scenarios effectively.
Reply to this answer
You're a bit confused there. While 'stubbing' can have slightly different meanings in various contexts, 'mock' is usually used consistently. It's pretty straightforward once you get the hang of it.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions