Testing data repositories with mocks
Having run our web controller through some automated testing, it’s time to switch our attention to another key piece of our system: the service layer that the web controller invokes.
Something that’s key is spotting any collaborators. Since the only service that’s injected into HomeController
is VideoService
, let’s take a closer look.
VideoService
, as defined in Chapter 3, Querying for Data with Spring Boot, has one collaborator, VideoRepository
. Essentially, to test out the VideoService
bean in a unit-test fashion, we need to isolate it from any outside influences. This can be accomplished using mocking.
Unit testing versus integration testing
There are various test strategies we can leverage. A key one is unit versus integration testing. In principle, a unit test is meant to only test one class. Any external services should be mocked or stubbed out. The counterpart test strategy, integration testing, involves...