Table of Contents
Test-Driven iOS Development with Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Your First Unit Tests
Building your first automatic unit test
What are unit tests?
Implementing a unit test example
Important built-in assert functions
Understanding TDD
The TDD workflow – red, green, and refactor
Red
Green
Refactor
TDD in Xcode
An example of TDD
Red – example 1
Green – example 1
Refactor – example 1
Red – example 2
Green – example 2
Refactor – example 2
A recap
Finding information about tests in Xcode
Test Navigator
Tests overview
Running tests
Running one specific test
Running all tests in a test case
Running a group of tests
The setUp() and tearDown() methods
Debugging tests
Breakpoint that breaks on test failure
Test again feature
Advantages of TDD
Disadvantages of TDD
What to test
Summary
2. Planning and Structuring Your Test-Driven iOS App
Task list view
Task detail view
Task input view
Structure of the app
The Table View Controller, the delegate and the data source
Table view cells
A model
Other view controllers
Development strategy
Getting started with Xcode
Setting useful Xcode behaviors for testing
Useful build behaviors
Testing behaviors
Summary
3. A Test-Driven Data Model
Implementing the ToDoItem struct
Adding a title property
Adding an itemDescription property
Removing a hidden source of bugs
Adding a timestamp property
Adding a location property
Implementing the Location struct
Adding a coordinate property
Implementing the ItemManager class
Count
Adding and checking items
Equatable
Removing all items
Ensuring uniqueness
Summary
4. A Test-Driven View Controller
Implementing ItemListViewController
Implementing ItemListDataProvider
Conducting the first tests
Fake objects
Using mocks
Checking and unchecking items
Implementing ItemCell
Implementing DetailViewController
Implementing InputViewController
Summary
5. Testing Network Code
Implementing asynchronous tests
Implementing a login request to a web service
Handling errors
Summary
6. Putting It All Together
Connecting parts
The initial View Controller
Showing the input view
Showing the detail view
Serialization and deserialization
Functional tests
Adding a UI test target
Recording and testing
Summary
7. Code Coverage and Continuous Integration
Enabling code coverage
Code coverage in Xcode
What code coverage is enough?
Continuous integration
Installing and setting up Xcode Server
Adding bots
Automatic deployment with fastlane
Installing fastlane
Setting up
Summary
8. Where to Go from Here
What we have learned so far
Integration tests
UI tests
Behavior-Driven Development
TDD in existing projects
More information about TDD
Summary
Index