Generating mocks with Sourcery

In this book, you created all the needed mocks yourself. You may have noticed that this is a boring task. Most mock classes consisted of mainly boilerplate code. Fortunately, there is a solution: Sourcery (https://github.com/krzysztofzablocki/Sourcery). From its GitHub page:

"Sourcery scans your source code, applies your personal templates, and generates Swift code for you, allowing you to use meta-programming techniques to save time and decrease potential mistakes."

There are many templates for common tasks that are ready to use. For example, there is a template to generate mock classes from protocols. Let's have a look how we could use Sourcery to generate a mock for ItemCell.

To enable Sourcery to generate ...

Get Test-Driven iOS Development with Swift 4 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.