S01E16: [TDD 🍅 13] Decoupling and Testing Modules with Swift Abstract Factories

In this episode, we continue the implementation of the NavigationControllerRouter by creating an abstract factory protocol, a factory test stub and a new type representing a Question.

As discussed in the previous episode, we decided to create an abstract factory to decouple the Routing module from the UI module, maintaining our architecture clean and flexible. To achieve that we create a factory protocol, agnostic of concrete implementations.

Just as our routing module shouldn't unnecessarily depend on other modules, neither should our routing tests. This will facilitate testing in isolation. To achieve this level of decoupling, we introduce a factory stub implementation to help us test the abstract factory usage in the NavigationControllerRouter.

As we’re testing the NavigationControllerRouter, we face a common UIKit problem that makes testing harder: asynchronous animation behavior. We show a simple and efficient solution to bypass it with a safe subclassing strategy.

Finally, we spike some solutions for adding a Question type. We decide to use an enum to box generic types and we test-drive its Hashable implementation.

Subscribe now to our Youtube channel and catch free new episodes every week and follow along the project's progress on GitHub.