#30daytestingchallenge
#day11of 30daytestingchallenge
As somebody relatively new and starting out in test automation, I tried to search for a beginner-friendly explanation of concepts of what on earth is stubbing, mocking and faking. Most definitions are technical as it is used in unit testing or test driven development (TDD).
If anyone has a better example or clearer understanding, please contribute to this thread.
Thank you.
From what I’ve gathered:
-
Test Double as the generic term for any kind of pretend object used in place of a real object for testing purposes. The name comes from the notion of a Stunt Double in movies.
-
Mocks and stubs are techniques that are used at the boundaries of the code under test.
-
Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.
-
There is a difference in that the stub uses state verification while the mock uses behaviour verification.
-
Fake objects actually have working implementations, but usually, take some shortcut which makes them not suitable for production (an in-memory database is a good example).
Sources: