I’m Ivan an iOS developer. At E&V Technology GmbH we make different mobile apps, helping our customers to find a property of their dream. One of these products is the Search app, having a more than 5 years history of exposing properties from the global E&V network for iPhone users.
When you develop the extendable app with a long-lifecycle the maintainability of the source code is of high importance. We want to be sure that every addition of a business value, that leads to the change of the source code, keeps the correct app’s behavior for the user. Either for a small feature or for a whole new screen.
To make this happen we split app code to units according to the Clean Architecture by R.C. Martin. And cover business logic and model units with tests. Each of these Unit Tests can be considered as a yes/no question to the app behavior and helps us to verify the correctness of the behavior after every change of the source code in seconds.
When you add Unit tests to a project, two general challenges arise.
- How to be sure that all necessary questions are asked to a program’s Unit?
- How to make sure that count of questions is small?
And the second challenge is critical for maintainability of unit tests code itself because if their count is too big then they become fragile, in other words, no one wants to support them and prefers to drop on the floor.
To deal with these challenges in iOS mobile apps we can do one more step. To write code that only satisfies tests, that is when we write a Test at first and only then we write an implementation of the Unit. This test-first approach has several advantages:
- Unit code is verified
- Count of necessary tests is minimal
- As a consequence, tests are easily maintainable
This is Test Driven Development!
Steps of TDD
Usually, three well-known steps of Test Driven Development are discussed. I prefer to consider four steps. The first step is to evolve a test list. The test list plays an important role in the method. This list is created from the user story you’re going to implement.