Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Test-Driven iOS Development with Swift 4 - Third Edition

You're reading from   Test-Driven iOS Development with Swift 4 - Third Edition Write Swift code that is maintainable, flexible, and easily extensible

Arrow left icon
Product type Book
Published in Oct 2017
Publisher Packt
ISBN-13 9781788475709
Pages 222 pages
Edition 3rd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dr. Dominik Hauser Dr. Dominik Hauser
Author Profile Icon Dr. Dominik Hauser
Dr. Dominik Hauser
Arrow right icon
View More author details
Toc

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 the code, we need to add a protocol with the methods that should be mocked. Imagine, we want to generate a mock for the method...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime