volume_mute
Mock Objects for Rare Events
publish date: 2026/06/17 05:25:32.379532 UTC
volume_mute
Beyond replacing slow dependencies, mock objects can also be used for another purpose in unit testing. What is this additional use?
Correct Answer
To simulate abnormal operations or rare events that are difficult to trigger in real systems
Explanation
Mock objects can simulate abnormal operations or rare events. For example, if a system is intended to take action at certain times of day, a mock object can return those specific times irrespective of the actual clock time. This allows testing of time-dependent or rare-condition behavior that would be impractical to trigger naturally.
Reference
Software Engineering, Ian Sommerville, 10th edition
