Chapter 6. Testing

A good test suite, like the solid foundation of a house, provides a known baseline of system behavior on top of which we can build confidently. That baseline gives us confidence to add features, fix bugs, and refactor without worrying that we’ll break other parts of the system. When integrated into a development workflow, that same test suite also encourages good practices by making it easier to maintain existing tests and add new ones.

Of course, foundations aren’t free. The effort of maintaining tests must be balanced with the value that the tests provide. If we spend all of our effort on testing, we’ll have none left to work on the rest of the system.

For serverless applications, drawing the line between valuable tests and brittle technical debt is harder than ever. Fortunately, we can use a familiar model to help consider the trade-offs.

The Test Pyramid

The classic “Test Pyramid” (from the 2009 book Succeeding with Agile by Mike Cohn, shown in Figure 6-1) is a useful guide in helping us decide which kinds of tests to write. The pyramid metaphor illustrates the trade-offs between the number of tests in a given slice, the value of those tests, and the costs to write, run, and maintain them.

images/ch06_image01.png
Figure 6-1. The Test Pyramid

Testing in a serverless world isn’t substantively different than in a traditional application, especially nearer the base of the pyramid. ...

Get Programming AWS Lambda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.