Understand the structure and use of unit tests.
- Test driven development aims to solve a critical problem, increasing application complexity and the inefficiency of human testing. In any great 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 at any time, they don't sleep. And together they make up a very powerful automated testing system for your application.
- Test-driven development: history and theory
- Creating a data model test
- Expanding tests
- Testing class methods
- Checking for duplicates
- Testing table views
- Mocking cells
- Testing cell selection
- Assembling the app