Hidden Dependencies - lovelejess/trivia GitHub Wiki
“I can’t get this class into a test harness”
Parameterize Constructor
-
Identify the constructor that you want to parameterize and make a copy of it.
-
Add a parameter to the constructor for the object whose creation you are going to replace. Remove the object creation and add an assignment from the parameter to the instance variable for the object.
-
If you can call a constructor from a constructor in your language, remove the body of the old constructor and replace it with a call to the old constructor. Add a new expression to the call of the new constructor in the old constructor. If you can’t call a constructor from another constructor in your language, you may have to extract any duplication among the constructors to a new method.
Try It Out!
- We can't write tests for MailingListDispatcher, it's calling out to our Exchange Server on construction. Fix this class using parameterize constructor so we can get it into a test harness.
Next Up: Now we're ready for Characterization Tests!