Mock Objects - Purpose and Use
publish date: 2026/06/19 10:51:13.299306 UTC
A team is implementing a component that sends emails via an external SMTP server. During unit testing, they do not want to send real emails but still need to verify that their component correctly formats and triggers email sends. What is the most appropriate approach?
Correct Answer
Explanation
A mock SMTP object has the same interface as the real email service but simulates its behavior - recording calls, checking parameters, and returning predetermined results without sending real emails. This allows fast, isolated unit testing of the email-sending component without requiring a live SMTP server, avoiding slow setup, side effects (real emails), and external dependencies.
Reference
Software Engineering, Ian Sommerville, 10th edition
