Modeling Testable Dependencies in iOS Codebases | by Eduardo Sanches Bocato | Apr, 2022

Code instance with choices for implementing testable dependencies in your challenge


If you end up creating an software and aiming for testability, it is good to have a normal concept of tips on how to outline your dependencies.

The examples beneath will current some choices on tips on how to obtain that.

If it should maintain some information or a state, it needs to be saved someplace within the reminiscence. Conserving that in thoughts, it’s greatest to implement it with a reference sort, on this case, a category.

If it doesn’t maintain information or state, you should utilize worth varieties, i.e. structs.

Utilizing Protocols

Utilizing protocols is the most typical solution to make one thing testable, extracting an interface/contract to symbolize the your dependency’s API. This manner we are able to use it together with dependency injection methods to attain the anticipated testability.

Utilizing Structs

This system leverages the ability of structs, representing the API as properties and setting the implementations when creating particular situations of them.

More Posts