Chapter 8. Organizing tests with factory functions
This chapter covers
- Understanding factory functions
- Using factory functions to organize tests
As a test suite grows in size, you start to see repeated code. One way to avoid this is to use factory functions to organize tests.
Factory functions are functions that return new objects or instances (you might know them as builders). You can add factory functions to tests that require repetitive setup to remove code duplication.
Using factory functions is a pattern that helps keep test code easy to read and understand. In this chapter, you’ll learn what factory functions are, how they can reduce repetition in tests, and how they improve your test code structure.
After you’ve learned what factory ...