Integrating Test Writing and Mocking Techniques in C++
Introduction
Welcome to the very last lesson of the "Increasing Code Test Coverage" course! In our journey so far, we've explored the importance of code coverage, the role of characterization tests, and how abstract classes and mocks can enhance testability. Now, we'll bring these concepts together to achieve comprehensive code coverage by integrating test writing and mocking techniques. This lesson will help you solidify your understanding and prepare you for practical application.
Whole Problem: The UserProcessor Class
Let's take a closer look at an implementation of a user processor. We want to add tests in order 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 UserProcessor class uses a UserDatabase class as a dependency. The UserDatabase class is designed to be overridden, allowing us to mock it in tests.
Practice Approach
First, we will focus on adding an abstract class 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.
