Lesson 33

Introduction to Test Driven Development

Test Driven Development (TDD) is an approach to software development that aims to reduce the number of bugs in the final product. A developer who practices TDD techniques not only writes actual code to carry out the app's functionality but also test code that ensures his applications code does what it is supposed to do.

This test code is called a unit test, and it is common for an application to have several hundred unit tests with each test testing a very small piece of the code base. The code that forms these unit tests is not part of the code base that will ship to the end users of the application. Typically these units tests are executed every time a developer attempts to create a build and if any unit tests were to fail then a build would not be created. TDD makes it very cost effective to catch regression bugs (bugs that were fixed at an earlier point in time but have been reintroduced due to subsequent development work).

It is not necessary for the same developer to write both the class as well as the test case. In fact, it is quite common for a senior developer to specify the behavior of a class for a junior developer by creating a bunch of unit tests. Given these tests, the junior developer can implement the class and knows his work is done when all the unit tests pass.

One of the key principles of TDD is that the tests are written first and development focuses on writing the minimum amount of code needed to make all ...

Get Swift iOS 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.