Book Image

Test-Driven iOS Development with Swift

By : Dr. Dominik Hauser
Book Image

Test-Driven iOS Development with Swift

By: Dr. Dominik Hauser

Overview of this book

Test-driven development (TDD) is a proven way to find software bugs early. Writing tests before your code improves the structure and maintainability of your app. Test-Driven iOS Development with Swift will help you understand the process of TDD and how it impacts your applications written in Swift. Through practical, real-world examples, you’ll start seeing how to implement TDD in context. We will begin with an overview of your TDD workflow and then deep-dive into unit testing concepts and code cycles. We will showcase the workings of functional tests, which will help you improve the user interface. Finally, you will learn about automating deployments and continuous integration to run an environment.
Table of Contents (15 chapters)
Test-Driven iOS Development with Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

TDD in existing projects


You most probably already have projects that have been implemented without any tests. It is much harder to add tests to an existing project than it is to write them first. When you don't keep in mind that you need to write a test for code sometime in the future, the code itself becomes hard to test. It is often easier to tie the different parts of the app together instead of keeping them separated with a clear and defined interface to each other. As a result, it becomes hard to separate micro features in order to test them with unit tests. In addition to this, testing methods with many side effects can be cumbersome to deal with.

When writing the tests initially, you automatically think about the tests. The code naturally becomes easier to test and more modular.

Back to your existing projects. What could you do to add tests? The way to go is to start small. Don't rewrite all the methods using TDD. This won't work, and you will most probably remove all the tests when...