Chapter 2. Planning and Structuring Your Test-Driven iOS App

In the previous chapter, we learned how to write unit tests, and we saw an easy example of TDD. When starting TDD, writing unit tests is easy for most people. The hard part is to transfer the knowledge from writing the test to driving the development. What can be assumed? What should be done before one writes the first test? What should be tested to end up with a complete app?

As a developer, you are used to thinking in terms of code. When you see a feature on the requirement list for an app, your brain already starts to layout the code for this feature. And for recurring problems in iOS development (such as building table views), you most probably have already developed your own best practices.

In TDD, you should not think about the code while working on the test. The tests have to describe what the unit under test should do and not how it should do it. It should be possible to change the implementation without breaking the tests.

To practice this approach of development, we will develop a simple to-do list app in the remainder of this book. It is, on purpose, not a very sophisticated app. We want to concentrate on the TDD workflow, not complex implementations.

This chapter introduces the app we are going to build, and it shows the views that the finished app will have.

We will cover the following topics in this chapter:

  • Task list view
  • Task detail view
  • Task input view
  • Structure of an app
  • Getting started with Xcode
  • Setting useful Xcode behaviors for testing

Task list view

When starting the app, the user sees a list of to-do items. The items in the list consist of a title, an optional location, and the due date. New items can be added to the list by an add (+) button, which is shown in the navigation bar of the view. The task list view will look like this:

Task list view

User stories:

  • As a user, I want to see the list of to-do items when I open the app
  • As a user, I want to add to-do items to the list

In a to-do list app, the user will obviously need to be able to check items when they are finished. The checked items are shown below the unchecked items, and it is possible to uncheck them again. The app uses the delete button in the UI of UITableView to check and uncheck items. Checked items will be put at the end of the list in a section with the Finished header. The user can also delete all the items from the list by tapping the trash button. The UI for the to-do item list will look like this:

Task list view

User stories:

  • As a user, I want to check a to-do item to mark it as finished
  • As a user, I want to see all the checked items below the unchecked items
  • As a user, I want to uncheck a to-do item
  • As a user, I want to delete all the to-do items

When the user taps an entry, the details of this entry is shown in the task detail view.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175