Doppelganger

Goal: learn about the various types of test doubles

Instructions

There are bugs in the code (marked with a Bug! comment), but all the tests are passing.

For each test, you will find a TODO comment. Your job is to implement a test double for each test, and to use it to make the test fail for the right reason, i.e, triggering the bugs. You must do so by adding only test code - you are not allowed to change the production code.

Here's the order in which you should fix the test - they go from easiest to trickiest :)

  1. SafeCalculator
  2. DiscountApplier
  3. MailSender

Step 1 - without any library

For this step, you are not allowed to add any external library.

Make a commit when you're done fixing all the TODOs

Step 2 - with a library

Use a library like mockito for Java, unittest.mock for Python or sinon for JavaScript to rewrite all the tests.

Make a second commit so you can compare test code with step 1.

Which version do you prefer?