2024-04-19 –, Sala 150
⏰ 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:
- set values for different parameters
- call different completions based on inputs
- 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! 🎬
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.
Meet Sara Sipione, an iOS Engineer at Qonto.
Currently based in the sunny island of Sicily, in southern Italy, Sara has studied and lived across Europe for about 10 years, falling in love with London, where she discovered the realm of iOS development.
While enjoying the busy life of the City and pub hopping after a long day at work, Sara developed excellent skills in building software with great attention to detail and focus on testability and QA. Lately, she has specialized in creating intuitive interfaces, consistently exploring new technologies, and expanding her knowledge.
Sara’s motto is “Creativity is seeing what others see and thinking what no one else ever thought.” - A. Einstein