Bringing Writing Tests and Mocks Together
Introduction
Welcome to the final lesson of the "Increasing Code Test Coverage" course! Throughout our journey, we've examined the significance of code coverage, the function of characterization tests, and how interfaces and mocks can improve testability. Now, we'll integrate these concepts to achieve thorough code coverage by combining test writing and mocking techniques. This lesson will help us solidify our understanding and prepare us for practical application.
Whole Problem: The UserProcessor Class
Let's examine an implementation of a user processor. We want to add tests to describe the characteristics of the system. We also don't want our tests to depend on a database. Let's take a closer look at the implementation of the UserProcessor class:
The class uses a UserDatabase class as a dependency. This class can be viewed below:
Practice approach
First, we will focus on adding an interface for the database layer to enable us to mock this particular dependency. After that, we will focus on writing a collection of tests that will describe the system and help us increase code test coverage for the UserProcessor class.
Best Practices for Test Writing
