Swift Heroes 2024

Swift Heroes 2024

Davide Tamiazzo

Davide is a Senior iOS engineer at Qonto, with a love for architectural challenges and always curious about what’s new in mobile development.
Experienced in developing in the FinTech space and passionate about personal finance and investments.


Your company

Qonto

Your job title

Senior iOS Engineer


Session

04-19
14:30
45min
A blazing fast and consistent generation of mocks with SwiftyMocky
Davide Tamiazzo, Sara Sipione

⏰ How long does it usually take you to set up mocks for your unit testing?
🤔 Have you ever wondered if there’s a faster and automated way to generate them?
🎢 Look no further than SwiftyMocky, an amazing open source library that generates mocks for any protocol!

Why SwiftyMocky

SwiftMocky allows to start unit testing any Swift component with ease by autogenerating corresponding mocks for its abstract dependencies.
It is as simple as that: add the Sourcery annotation

//sourcery: AutoMockable

to any protocol and SwiftyMocky autogenerates a corresponding mock for which you can:

  1. set values for different parameters
  2. call different completions based on inputs
  3. check the actual calls being performed on that dependency

Takeaways

  • Expands the scope of your unit testing → before this, we were only testing results with XCTAssertions 🙅
  • It lightens the burden of unit testing on your team by automating a repetitive task → our team re-generates mocks 5 to 10 times a day, it must be easy! 🚀
  • The command swiftymocky generate has a smart caching system and is able to generate a new mock in as little as 0.1 seconds 🏎️ → in our project, <2 sec for features = <300 mocks, ~50 sec for the whole app = ~3000 mocks
  • support for Concurrency and Generics

Additional improvements

We will also showcase how to improve on the default output, which is a single Mock.generated.swift file, which can minimize parallelization, by splitting it into one file per protocol → we reduced our CI run time by ~46.36% - check out this blog post by Ruslan Alikhamov!

Project showcase

Download the sample project we created to see it in action! 🎬

Sala 150