O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testability

There is no need for a mocking framework to write unit tests that deal with value types. We can directly define values indistinguishable from the instances in our applications.

If we use reference types that behave, we have to test the interactions between the reference type that we will test and the rest of the system. This typically means a lot of mocking or extensive setup code to establish the required relationships.

In contrast, value types are isolated and interchangeable, so we can directly define a value, call a method, and examine the result. Simpler tests with greater coverage yield a code that is easier to change and maintain.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required