Chapter 2. What is a unit test?

 

This chapter covers

  • What a unit test is
  • The differences between shared, private, and volatile dependencies
  • The two schools of unit testing: classical and London
  • The differences between unit, integration, and end-to-end tests

As mentioned in chapter 1, there are a surprising number of nuances in the definition of a unit test. Those nuances are more important than you might think—so much so that the differences in interpreting them have led to two distinct views on how to approach unit testing.

These views are known as the classical and the London schools of unit testing. The classical school is called “classical” because it’s how everyone originally approached unit testing and test-driven development. The London school takes root in the programming community in London. The discussion in this chapter about the differences between the classical and London styles lays the foundation for chapter 5, where I cover the topic of mocks and test fragility in detail.

Let’s start by defining a unit test, with all due caveats and subtleties. This definition is the key to the difference between the classical and London schools.

2.1. The definition of “unit test”

There are a lot of definitions of a unit test. Stripped of their non-essential bits, the definitions all have the following three most important attributes. A unit test is an automated test that

  • Verifies a small piece of code (also known as a unit),
  • Does it quickly,
  • And does it in an isolated manner.

2.2. The classical and London schools of unit testing

2.3. Contrasting the classical and London schools of unit testing

2.4. Integration tests in the two schools

Summary

sitemap