Writing Testable Code

The Xcode integrated support for unit-testing makes it possible for you to build test suites to support your development efforts in any way you want. You can use unit-testing in Xcode to detect potential regressions in your code or to validate the behavior of your app. This testing can improve the stability of your code by ensuring that units behave in the expected ways.

Of course, the level of stability you achieve through unit-testing is highly dependent on the quality of the test cases you write. Follow these guidelines as you write code, to ensure that it’s easily testable: