Connect with us

Articles

Modeling Testable Dependencies in iOS Codebases

The examples below will present some options on how to achieve that.

When you are developing an application and aiming for testability, it’s good to have a general idea of how to define your dependencies.

The examples below will present some options on how to achieve that.

1. Dependencies that store data or an internal state

If it will hold some data or a state, it should be stored somewhere in the memory. Keeping that in mind, it’s best to implement it with a reference type, in this case, a class.

2. Dependencies that do not store data or state

If it does not hold data or state, you can use value types, i.e. structs.

Using Protocols

Using protocols is the most common way to make something testable, extracting an interface/contract to represent the your dependency’s API. This way we can use it along with dependency injection techniques to achieve the expected testability.

Using Structs

This technique leverages the power of structs, representing the API as properties and setting the implementations when creating special instances of them.

Full Article: Eduardo Sanches Bocato @ Medium
👋: 93
Apr 22, 2022
Advertisement

Trending