2 What to test and when

 

This chapter covers:

  • The different kinds of tests and when to use them
  • Writing your first automated tests
  • How to balance coupling, maintenance, and cost

In the previous chapter, to facilitate explaining what tests are and what are their benefits, I've put all the different kinds of tests in a single big conceptual box. I showed tests which dealt with databases, that directly called one function, and others that called multiple functions. In this chapter, I'll take tests out of that box and put them into separate shelves, each one containing tests of a different kind.

It's essential to understand how tests fit into different categories because different kinds of tests serve different purposes. When building a car, for example, it's crucial to test the engine and the ignition system individually, but it's also vital to ensure they work together. If not, both the engine and the ignition system are useless. It's equally as important to test whether people can drive the car once all parts are in place, or else nobody will go anywhere.

When we build software, we want to have similar guarantees. We want to ensure our functions work in isolation as well as in integration. And, when we put all of these functions together in an application, we want to ensure customers can use it.

2.1 The testing pyramid

2.2 Unit Tests

2.3 Integration Tests

2.4 End-to-end tests

2.4.1 Testing HTTP APIs

2.4.2 Testing GUIs

2.4.3 Acceptance tests and End-to-end tests are not the same

2.5 Exploratory testing and the value of QA

2.6 Tests, cost, and revenue

2.7 Summary

sitemap