Chapter 9. Speeding up test execution

 

In this chapter

  • Finding the root causes why a build is slow
  • How to make test code run faster
  • How to tweak an automated build to run faster

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:

  1. Speeding up tests
  2. 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.

9.1. Looking for a speed-up

9.2. Speeding up test code

9.3. Speeding up the build

9.4. Summary

sitemap