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

Our mutable example's addNewProduct() method has no return values. While it is possible to write a unit test for it, it is not obvious how we should implement asserting because the method causes a side-effect in our existing instance that we need to know about.

Our immutable example's addNewProduct() method returns a new array of product. We simply inspect the value of products and assert. We still have both the old and new instances, so we have everything we need to ensure that our code works as intended.

Although we do not cover unit-testing in this book, it is highly recommended that you explore QuickCheck-based libraries such as Quick (https://github.com/Quick/Quick) and SwiftCheck (https://github.com/typelift/SwiftCheck

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