From the course: iOS App Development: Test-Driven Development

Unit tests explained

From the course: iOS App Development: Test-Driven Development

Start my 1-month free trial

Unit tests explained

- Test-driven development aims to solve a critical problem: increasing application complexity and the inefficiency of human testing. Now, in any good development system, we need great tools, and that's where unit tests come in. At this level of abstraction, an analogy is very useful when learning a new skill, so let's start with that. A test suite is like a living organism. It has different functional parts which are made up of smaller and smaller functional blocks, which in turn are made up of atoms at the most basic level. In this case, individual unit tests are the atoms, the smallest level of functionality in the test suite. The test suite functions like your application's immune system. The stronger it is, the less likely your app is to break down. We'll carry this analogy through to the conclusion when we talk about code coverage at the end of the course, so keep it in the back of your mind when you get stuck. Analogies aside, unit tests have a specific definition. Each individual unit test is only concerned with testing one thing at a time. This can be anything from variable initialization and interface configuration to asynchronous API calls and custom protocols. Whatever your unit tests are testing, the goal is always to prove that your code is working the way you want it to and not the way you assume it will. Defensive programming like this will give you greater confidence in your code base as it grows. Think of your unit tests like helper minions. You tell them what to test and when and let them do the work. You can call on them anytime. They don't sleep. And together they make up a very powerful automated testing system for your application.

Contents