Fast Tests
Learn some approaches to make our test suite run faster.
We'll cover the following...
As our application and test suite grow, it will take longer to run the full set of tests. Having fast tests is very important because it allows a fast feedback loop. Developers can add or refactor a few lines of code and run the test suite to ensure they didn’t break anything. Ideally, our entire test suite would take no more than a few minutes to run. If test suites take very long to run, say 10 minutes, we’ll be tempted to skip running them and lose many of the benefits of testing. We can consider several approaches to ensure we have a fast test suite:
- Write mostly unit tests.
- Analyze our tests to identify the slowest ones.
- Mock slow operations, like API calls.
- Use a tool to run our tests in parallel.
- Update Jasmine and any frameworks we are using.
The testing pyramid
A popular idea in test-driven development (TDD) is the testing pyramid, which is the idea that we should write mostly unit tests. This is not a strict rule, and it will depend on the size of our projects and our team’s needs. However, a compelling reason to focus on unit tests is that they run much faster. If we build a large application with many features, we likely end up with a large test suite. A good unit test executes only a tiny piece of functionality and runs incredibly quickly. In many projects, it’s possible to run thousands ...