Chapter 9. Speeding up test execution
In this chapter
By now you’ve formulated an idea about why you write automated unit tests and what makes (or doesn’t make) for a good unit test. One of the properties of a good unit test is that it runs fast. Nevertheless, as you accumulate a bigger and bigger suite of tests, your feedback loop grows too. This chapter explains strategies for speeding up the execution of your test suite—the time it takes to run all of your unit tests—so that you’ll get that precious feedback in a timely manner.
First, we’ll get to the bottom of why we’re looking for faster test execution and faster build times. Then, we’ll draw an overall strategy for taking on a slow build. There are two parts to that strategy and the majority of this chapter is focused on those two missions:
- Speeding up tests
- Speeding up a build
Speeding up tests means diving into the code base to find opportunities for making tests run faster. We’ll look at slowness inherited from the class hierarchy of our tests, we’ll take a critical look at what code we’re executing during our tests, and we’ll pay special attention to any place where we access the network, a database, or the plain old filesystem.