Khaled El-Morabea and Hassaan El-Garem
Modularizing Legacy Projects Using TDD
Test-Driven Development with XCTest for iOS
1st ed.
Logo of the publisher
Khaled El-Morabea
Giza, Egypt
Hassaan El-Garem
Cairo, Egypt
ISBN 978-1-4842-7427-9 e-ISBN 978-1-4842-7428-6
https://doi.org/10.1007/978-1-4842-7428-6
Khaled El-Morabea and Hassaan El-Garem 2021
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
When I started writing this book, it was in the middle of the pandemic, and we had a new arrival to our family, Noah. It was a tough period. Imagine raising a new baby during the pandemic and with all these restrictions to stay at home and you need to focus on writing your first book. So I would like to dedicate this book to my wife, Yasminawithout her help and support, it wouldnt have been possible. And to my parents, Huda and Mohamedwithout their continuous support and love, I wouldnt be where I am now.
Khaled El-Morabea
To my sister, Rana, for pushing me to take on this challenging yet fulfilling project. And to my parents, Sahar and Saleh, for their unending love and their much-needed emotional support. And to Aya, without her love and support, this book would have never seen the light of day.
Hassaan El-Garem
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/978-1-4842-7427-9. For more detailed information, please visit http://www.apress.com/source-code.
Acknowledgments
We would like to thank the many people who helped us write this book. We are very grateful to Vishwesh Shrimalihis constant and thorough feedback was integral in making this book. We would also like to thank Moataz Soliman, Ahmed AbouElhamayed, Mahmoud Othman, Aprille Muscara, and Anwar El-Wakilwithout their feedback, this book wouldve been in a much worse state. We also thank Aaron Black, for believing in this project from day one. And, finally, we especially thank our editor, Jessica Vakili, who was extremely supportive throughout the whole process of writing this book.
Table of Contents
About the Authors
Khaled El-Morabea
is an engineering manager at Instabug. He has been an iOS developer for more than 8 years and leading the iOS team for more than 3 years. In that time he has worked on several projects. During his time at Instabug, he has worked on multiple integral products, both as a developer and as a strategic engineering manager.
Hassaan El-Garem
has been involved in the field of iOS development for 5 years, during which he worked on multiple apps and projects. He has a passion for testing and for working on complex projects while maintaining the highest level of quality. Following his passion for testing has led him to create a closed-source testing framework used for randomized stress testing.
About the Technical Reviewer
Vishwesh Ravi Shrimali
graduated in 2018 from BITS Pilani, where he studied mechanical engineering. Since then, he has worked with Big Vision LLC on deep learning and computer vision and was involved in creating official OpenCV AI courses. Currently, he is working at Mercedes-Benz Research and Development India Pvt. Ltd. He has a keen interest in programming and AI and has applied that interest in mechanical engineering projects. He has also written multiple blogs on OpenCV and deep learning on LearnOpenCV, a leading blog on computer vision. He has also coauthored Machine Learning for OpenCV 4 (Second Edition) by Packt. When he is not writing blogs or working on projects, he likes to go on long walks or play his acoustic guitar.
Khaled El-Morabea and Hassaan El-Garem 2021
K. El-Morabea, H. El-Garem Modularizing Legacy Projects Using TDD https://doi.org/10.1007/978-1-4842-7428-6_1
1. TDD Basics
A developer is a craftsman, a skilled individual driven by passion. Most developers enjoy what they do for a living, to the extent that a lot of developers choose coding as their secondary hobby in their free time. They are proud of what they develop and set high quality standards for their work. Nothing feels better than releasing new code that works well and meets users expectations. The user here could be the customer or the developer who developed the code themselves. This is important to realize. This sets the intention of the developer as someone who wants to produce high-quality results.
It is no secret that everyone out there including you wants their software projects to be of the highest quality. Yet achieving such a standard isnt particularly easy, and maintaining it can be even harder. Lets say you have worked on an MVP (Minimal Viable Product) and it got released. In most cases this is not the end of the story. Youll probably keep on adding features to it. At some point youll even realize you need to rewrite a big part of your code or swipe out a dependency for another. These constant changes will eventually compromise your projects quality. Even bug fixes can make a dent at your quality. Its very common to fix one bug and have it cause another more serious bug someplace else. So how can we reach a high quality standard and maintain it? We need to have constant feedback that tells us if our changes introduce any issues. And how can we get such feedback? The answer is simple: testing.
Types of Testing
There is more than one type of testing you can utilize to address these problems. The first solution we will discuss is manual testing. Manual testing is a type of testing in which test cases are executed manually either by a tester or directly by the developer. Manual testing in many cases is considered to be an imperative part of the software cycle. Good testers often have a knack of thinking of highly irregular scenarios, which ultimately leads to identifying hidden bugs.