Test-Driven iOS Development with Swift 4
Third Edition
Write Swift code that is maintainable, flexible, and easily extensible
Dr. Dominik Hauser
BIRMINGHAM - MUMBAI
Test-Driven iOS Development with Swift 4
Third Edition
Copyright 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: February 2016
Second edition: October 2016
Third edition: October 2017
Production reference: 1271017
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78847-570-9
www.packtpub.com
Credits
Author Dr. Dominik Hauser | Copy Editors Charlotte Carneiro Safis Editing |
Reviewer S Ravi Shankar | Project CoordinatorSheejal Shah |
Commissioning Editor Kunal Chaudhari | ProofreaderSafis Editing |
Acquisition EditorReshma Raman | IndexerFrancy Puthiry |
Content Development EditorJason Pereira | Production Coordinator Shraddha Falebhai |
Technical Editor Prajakta Mhatre |
About the Author
Dr. Dominik Hauser completed his PhD in physics from the University of Heidelberg. While working as a university professor, he started iOS development in his spare time. His first app on physics has been an astounding success worldwide. Since then, he has turned himself into a full-time iOS developer, with a number of successful apps to his name. He has been a Swift developer since day one and runs a blog on iOS development.
About the Reviewer
S Ravi Shankar is a multi-skilled software consultant with over 17+ years of experience in IT industry. He has a good all-around ability to work in different technologies and extensive experience in product development, system maintenance, and support. He is a polyglot and a self-taught programmer with hands-on experience in Swift, Objective-C, and Java.
It was a pleasure to work with Sheejal, project coordinator at Packt, and thanks to Packt for giving me this opportunity.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com . Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Why subscribe?
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1788475704 .
If you'd like to join our team of regular reviewers, you can e-mail us at customerreviews@packtpub.com. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
iOS projects have become bigger and more complex. Many projects have already surpassed desktop applications in their complexity. One important strategy to manage this complexity is through the use of unit tests. By writing tests, a developer can point out the intention of the code and provide a safety net against the introduction of bugs.
By writing tests first (test-driven development), the developer focuses on the problem. This way, they are forced to think about the domain and rephrase a feature request using their own understanding by writing the test. In addition to this, applications are written using TDD only containing code that is necessary to solve the problem.
As a result, the code is clearer, and the developer gains more confidence that the code actually works.
In this book, you will develop an entire iOS app using TDD. You will experience different strategies for writing tests for models, view controller, and networking code.
What this book covers
, Your First Unit Tests , walks you through your first unit tests using Xcode and discusses the benefits of using TDD.
, Planning and Structuring Your Test-Driven iOS App , introduces the app you are going to write through the course of this book and how to set up a project in Xcode.
, A Test-Driven Data Model , discusses the TDD of a data model.
, A Test-Driven View Controller , shows you how to write tests for a view controller, and describes how to use fake objects to isolate micro features for the test.
, Testing Network Code , teaches you to test network code using stubs to fake a server component before it is developed.
, Putting It All Together , walks you through the integration of all the different parts developed in previous chapters and shows the use of functional tests.
, Code Coverage , shows you how to measure the code coverage of your tests using Xcode.
, Where to Go from Here , wraps up and shows you the possible next steps to improve your acquired testing skills.
What you need for this book
The following hardware and software is needed to follow the code examples in
Next page