CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 1 of 6 · 1 min read

Why this page comes fifth in Level 5

In this module you will

  • Say which design choices make code easy or hard to test.
  • Inject a clock, a store and a notifier so a test can control them.
  • Write a fake and a recording object by hand.
  • Write a short, readable test with one idea in it.
  • Apply the five F.I.R.S.T. rules and the three laws of test-driven development.

Level 2 showed that depending on abstractions helps tests. Level 3 showed that injecting dependencies puts that into practice. This page ties them together. In a design round, "how would you test this" is a common follow-up, and the answer shows whether the design is sound. A class that cannot be tested without a database and a real clock is usually a class with hidden dependencies. The sources are "Clean Code" (CC) chapter 9, "Clean Architecture" (CA), and "Effective Java" (EJ). The tests below were run with a small hand-made check function. They are written here in the same style as JUnit tests, which is the usual Java test library. Numbers marked "made up" only show the idea.