Difference between revisions of "Mocking Frameworks"
Line 12: | Line 12: | ||
=== Mocking === | === Mocking === | ||
Mocking is a process used in unit testing when unit being tested has external dependencies.It creates mock objects (also known as replacement or dummy objects) that can be used in the simulation of real objects.The main purpose of this process is isolation code for testing rather than concentrating on the behaviour or state of external dependencies.Mocking comes in three flavors: fakes, stubs and mocks. The fakes are the simplest. They are used when you want to test the behavior of a class that has no dependencies. The stubs are used when you want to test the behavior of a class that has dependencies and you do not want to change the behavior. The mocks are used when you want to test the behavior of a class that has dependencies and potentially modify behaviors. | |||
Mocking is normally required when components under test has dependencies with no implementation or with implementation in progress(eg:REST APIs) or when components update system state(DB calls). | |||
=== Mocking Frameworks === | === Mocking Frameworks === |
Revision as of 23:08, 23 January 2023
Summary
This document gives basic insights about Mocking and Mocking Frameworks with their usages, advantages and disadvantages. Also, some code examples showing mock testing demo using Frameworks like Mock(Python), Mockito(Java) and Moq(.NET) are also given.
Requirements
- Operating system:
- Packages: unittest.mock (Python), org.mockito.Mockito(Java) and Moq(.NET)
Description
Mocking
Mocking is a process used in unit testing when unit being tested has external dependencies.It creates mock objects (also known as replacement or dummy objects) that can be used in the simulation of real objects.The main purpose of this process is isolation code for testing rather than concentrating on the behaviour or state of external dependencies.Mocking comes in three flavors: fakes, stubs and mocks. The fakes are the simplest. They are used when you want to test the behavior of a class that has no dependencies. The stubs are used when you want to test the behavior of a class that has dependencies and you do not want to change the behavior. The mocks are used when you want to test the behavior of a class that has dependencies and potentially modify behaviors. Mocking is normally required when components under test has dependencies with no implementation or with implementation in progress(eg:REST APIs) or when components update system state(DB calls).
Mocking Frameworks
Make sure to read
- War and Peace
- Lord of the Rings
- The Baroque Cycle
Used Hardware
Device to be used with this documentation Maybe another device to be used with this documentation
Courses
- A course where this documentation was used (2017, 2018)
- Another one (2018)