Chapter 2. In search of good

 

In this chapter

  • What makes a test “good”?
  • Testing relevant behavior
  • The importance of reliable tests

We’re on a journey of learning about good tests. We want to learn to identify good tests, write good tests, and improve not-so-good tests so they become good tests—or at least closer to being good tests. The question is, What makes a test “good”? What are the magic ingredients? There are several aspects to consider, including:

  • The test code’s readability and maintainability
  • How the code is organized both within the project and within a given source file
  • What kinds of things a test is checking for
  • How reliable and repeatable a test is
  • How a test makes use of test doubles

We’ll be taking a closer look at all of these aspects in this chapter.

The preceding list is far from being comprehensive. The range of factors that may tip your test-quality scale either way is endless. Similarly, some of the factors don’t matter that much in all contexts. For some tests, their execution speed may be crucial, whereas for other tests, being extremely focused is key.

2.1. Readable code is maintainable code

2.2. Structure helps make sense of things

2.3. It’s not good if it’s testing the wrong things

2.4. Independent tests run easily in solitude

2.5. Reliable tests are reliable

2.6. Every trade has its tools and tests are no exception

2.7. Summary