Mocking constructors (Medium)
At times, we come across a class that does a lot of work in its constructor itself. This can cause the constructor to become overly complicated and a road block for testing other classes.
In this recipe, we will learn how to mock and verify the invocation of a constructor.
A new requirement has come up while creating new employees. We want to send an e-mail message to welcome the new employees.
We will encapsulate the functionality of sending an e-mail in a class called
WelcomeEmail. With this requirement in mind, let's look at how we can mock and verify constructors.
How to do it...
- Let's start off by creating a class called
/** * The class that is responsible to send the Welcome Email * to new ...