Book Image

Test-Driven iOS Development with Swift

By : Dr. Dominik Hauser
Book Image

Test-Driven iOS Development with Swift

By: Dr. Dominik Hauser

Overview of this book

Test-driven development (TDD) is a proven way to find software bugs early. Writing tests before your code improves the structure and maintainability of your app. Test-Driven iOS Development with Swift will help you understand the process of TDD and how it impacts your applications written in Swift. Through practical, real-world examples, you’ll start seeing how to implement TDD in context. We will begin with an overview of your TDD workflow and then deep-dive into unit testing concepts and code cycles. We will showcase the workings of functional tests, which will help you improve the user interface. Finally, you will learn about automating deployments and continuous integration to run an environment.
Table of Contents (15 chapters)
Test-Driven iOS Development with Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Implementing a login request to a web service


Let's assume that a colleague is developing a web service, but it is not finished yet. However, we already know what the API will look like. There will be an endpoint for the login. The URL will be https://awesometodos.com/login; it will take two parameters, a username and password, and it will return a token that has to be used with each call to the API.

We need a test that asserts that the token, returned from the login call, is stored somewhere for later use. Tokens should be stored in the iOS keychain. Keychain access is managed by a very low-level API. This means that it is a bit complicated to build a class accessing keychain items (but it's easier than you might think). Because of this, there are a lot of available open source frameworks for reading from and writing to the keychain. Implementing keychain access is beyond the scope of this book. Instead, we will add a protocol that defines the methods that the keychain manager should implement...