Learn how to test iOS Applications! iOS Test-Driven Development introduces you to a broad range of concepts with regard to not only writing an application from scratch with testing in mind, but also applying these concepts to already written applications which have little or no tests written for their functionality. Who This Book Is For This book is for intermediate iOS developers who already know the basics of iOS and Swift development but want to learn how to write code which is both testable and maintainable. Topics Covered in iOS Test-Driven Development The TDD Cycle: Learn the concepts of Test-Driven Development and how to implement these concepts within an iOS application. Test Expressions and Expectations: Learn how to test both synchronous code using expressions and asynchronous code using expectations. Test RESTful Networking: Write tests to verify networking endpoints and the ability to mock the returned results. Test Authentication: Write tests which run against authenticated endpoints. Legacy Problems: Explore the problems legacy applications written without any unit tests or without thought of testing the code. Breaking Dependencies into Modules: Learn how to take dependencies within your code and compartmentalize these into their own modules with their own tests. Refactoring Large Classes: Learn how to refactor large unweilding classes into smaller more manageable and testable classes / objects. One thing you can count on: after reading this book, you’ll be prepared to write testable applications which you can have confidence in making changes too with the knowledge your tests will catch breaking changes. Introduction About this book Section introductions How to read this book What You Need Book License Book Source Code & Forums Chapter 1: What Is TDD? Why should you use TDD? What should you test? But TDD takes too long! When should you use TDD? Key points Chapter 2: The TDD Cycle Getting started Red: Write a failing test Green: Make the test pass Refactor: Clean up your code Repeat: Do it again TDDing init(availableFunds:) TDDing addItem Adding two items Challenge Key points Chapter 3: TDD App Setup About the FitNess app Your first test Red-Green-Refactor Test nomenclature Structure of XCTestCase subclass Your next set of tests Using @testable import Testing initial conditions Refactoring Challenge Key points Where to go from here? Chapter 4: Test Expressions Assert methods View controller testing Test ordering matters Code coverage Debugging tests Challenge Key points Where to go from here? Chapter 5: Test Expectations Using an expectation Testing for true asynchronicity Waiting for notifications Showing the alert to a user Getting specific about notifications Driving alerts from the data model Using other types of expectations Challenge Key points Where to go from here? Chapter 6: Dependency Injection & Mocks What's up with fakes, mocks, and stubs? Understanding CMPedometer Mocking Handling error conditions Getting actual data Making a functional fake Wiring up the chase view Time dependencies Challenge Key points Where to go from here? Chapter 7: Introducing Dog Patch Getting started Understanding Dog Patch's architecture Where to go from here? Chapter 8: Networking client Getting Started Setting up the networking client TDDing the networking call Dispatching to a response queue Key points Chapter 9: Using the Network Client Getting started Creating a shared instance Adding a network client property Using the network client Creating the network client protocol Creating the mock network client Using the mock network client Key points Chapter 10: Image Client Getting started Setting up the image client Creating an image client protocol Downloading an image Caching Setting an image view from a URL Using the image client Key points Chapter 11: Legacy Problems Introducing MyBiz Identifying a change point Finding a test point Breaking dependencies Writing tests Making a change and refactoring Challenges Key points Where to go from here? Chapter 12: Dependency Maps Getting started Choosing where to begin Finding direct dependencies Finding secondary dependencies Deciding when to stop What are problematic dependencies? Finding problematic dependencies Completing the map Breaking up complex systems Key Points Where to go from here? Chapter 13: Breaking Up Dependencies Getting started Characterizing the system Breaking up the API/AppDelegate dependency Breaking the AppDelegate dependency Breaking the ErrorViewController dependency Challenge Key Points Where to go from here? Chapter 14: Modularizing Dependencies Moving files Using the new framework with Login Fixing MyBiz Wrap up Challenges Key points Where to go from here? Chapter 15: Adding Features to Existing Classes Getting started Sending reports Adding analytics to the view controllers Passing around dependencies Challenge Key points Where to go from here?