Modularizing Legacy Projects Using TDD : Test-Driven Development with XCTest for IOS 🔍
Khaled El-Morabea;Hassaan El-Garem;(auth.)
Apress : Imprint: Apress, 1st ed. 2021, Berkeley, CA, 2021
英语 [en] · PDF · 7.8MB · 2021 · 📘 非小说类图书 · 🚀/lgli/lgrs/upload · Save
描述
Improve current or new projects with top notch testability and maintainability. Writing tests improves the design of your apps, as it pushes you to have a more modularized design. This in turn improves the maintainability and sustainability of your apps. This book is for iOS developers who already know the basics of iOS and Swift development but want to learn all the testing pro features in iOS.
You'll start by reviewing the TDD Cycle and how to implement these concepts on a legacy project or a new one. You'll then walk through TDD step-by-step on a blank project, including setting up test targets, assertions, and expectations. You'll follow that with all levels of testing such as unit tests, integration tests, and end-to-end tests, and also tackle fairly complex, yet badly written legacy code.
The book will take you through the journey of modularizing a legacy app using TDD. Throughout this journey, you will be introduced to multiple testingconcepts and techniques, like writing tests for network and core data layers. You will write tests to ensure the thread safety of your app. And you’ll add a new feature while you are in the middle of refactoring, which is an important skill so you can keep adding features while you are fixing your technical debt. By the end of this book, you will have all the tools needed to become a testing master.
What You'll Learn Use mocking and dependency injection to make components more testable
Write tests for asynchronous code like network code
Add new features to existing legacy apps using TDD
Who This Book Is For
Experienced iOS developers who care about software quality and meeting customer expectations.
You'll start by reviewing the TDD Cycle and how to implement these concepts on a legacy project or a new one. You'll then walk through TDD step-by-step on a blank project, including setting up test targets, assertions, and expectations. You'll follow that with all levels of testing such as unit tests, integration tests, and end-to-end tests, and also tackle fairly complex, yet badly written legacy code.
The book will take you through the journey of modularizing a legacy app using TDD. Throughout this journey, you will be introduced to multiple testingconcepts and techniques, like writing tests for network and core data layers. You will write tests to ensure the thread safety of your app. And you’ll add a new feature while you are in the middle of refactoring, which is an important skill so you can keep adding features while you are fixing your technical debt. By the end of this book, you will have all the tools needed to become a testing master.
What You'll Learn Use mocking and dependency injection to make components more testable
Write tests for asynchronous code like network code
Add new features to existing legacy apps using TDD
Who This Book Is For
Experienced iOS developers who care about software quality and meeting customer expectations.
备用文件名
lgli/P:\springer_dnd140621\springer\10.1007%2F978-1-4842-7428-6.pdf
备用文件名
lgrsnf/3956.pdf
备选标题
Modularizing legacy projects using TDD : test-driven development with ZCTest for iOS
备选标题
MODULARIZING LEGACY PROJECTS USING TDD : test driven development with xctest for ios
备选作者
El-Morabea, Khaled; El-Garem, Hassaan
备选作者
Khaled El-Morabea; Hassaan El-Garem
备选作者
KHALED ELGAREM, HASSAAN ELMORABEA
备用出版商
Apress, Incorporated
备用出版商
Springer Nature
备用出版商
Apress L. P.
备用版本
United States, United States of America
备用版本
Springer Nature, Berkeley, CA, 2021
备用版本
New York, 2021
备用版本
3, 20211025
备用版本
S.l, 2022
备用版本
PS, 2021
元数据中的注释
producers:
Adobe PDF Library 10.0.1
Adobe PDF Library 10.0.1
备用描述
Table of Contents 5
About the Authors 13
About the Technical Reviewer 14
Acknowledgments 15
Chapter 1: TDD Basics 16
Types of Testing 17
Trouble with Automated Testing 18
TDD in a Nutshell 18
Why Use TDD? 20
External and Internal Quality 21
When to Use TDD? 22
When Not to Use TDD? 23
Refactoring 23
Modularization 23
Test Structure 24
Let’s TDD 24
Maximum Out of TDD 28
Exercise 31
Summary 32
Chapter 2: Unit Tests 34
Your First Test 34
What Do We Want to Test? 35
Creating a Unit Test Target 36
Adding a Test Case Class 38
Assert Methods 40
Assert Method Types 43
Truthfulness Asserts 43
Equality Asserts 43
Nullability Asserts 44
Comparison Asserts 46
Errors Asserts 47
Expectations 48
Expectation Types 50
Test Ordering 51
Randomized Ordering 53
Code Coverage 54
Exercise 56
Summary 57
Chapter 3: UI Tests 59
Your First Test 59
XCUITest Components 63
Our Chapter Goal 64
First Test Case 64
Launching the App 64
Querying the UI 65
Relationships 65
Interacting with the UI 68
UI Events 70
Assertions 70
Value Assertion 71
Accessibility 71
Accessibility Tips 73
Putting It All Together 75
Improve UI Tests 76
Exercise 77
Summary 77
Chapter 4: Testing Pyramid 79
Our App 80
UI Tests 81
Integration Tests 84
Unit Tests 91
Summary 95
Chapter 5: TDD Deep Dive 98
CoffeePot 98
Eye on the Big Picture 99
Requirements 100
Testing Pyramid 102
First Story 103
Architecture 104
MVP 105
First Integration Test 106
Unit Tests 109
CoffeeDrinksDataSource 109
CoffeeDrinksModelTests 111
CoffeeDrinksPresenterTests 115
Test Health Check 120
Second Story 122
Architecture 124
Exercise 129
Summary 129
Chapter 6: Modularization for the Win 131
Why Bother with Modularization? 131
What Is a Module? 134
Modularizing Your App 138
Introducing Books 140
Modularization Process 143
Initial Module Map 144
Choose a Class as a Starting Point 145
Identify the Class’s Responsibilities 146
Refactor Responsibilities 147
Verification Tests 148
Refactoring 149
Integration Test 151
NetworkLayer 153
MainViewModel 154
MainViewPresenter 158
Last Touches 161
Test Value 162
Rerun Verification Tests 163
Refactor the Rest of the Responsibilities 164
Next Starting Point 165
Exercise 165
Summary 165
Chapter 7: Dependency Injection and Mocks 168
Stubbing 168
Mocking 171
Test Doubles Creation 174
Creation Using Inheritance 174
Creation Using Protocols 176
Dependency Injection 179
Initializer Injection 180
Property Injection 181
Stubbing the Network in UI Tests 182
Summary 191
Chapter 8: Avoiding Multithreading Nightmares 193
What Is Concurrency? 193
GCD 194
Queues 194
Serial vs. Concurrent 195
Sync vs. Async 196
Cost of Concurrency 198
Reader-Writer Problem 200
Singleton Classes 200
Identifying a Race Condition 201
Applying TDD to the Problem 203
Thread Sanitizer 211
Make It Pass 213
Fixing Threading Issues in Books 215
Applying TDD 217
Summary 220
Chapter 9: Testing Your Network 222
Networking ABCs 222
HTTP Requests 223
HTTP Responses 223
URL 224
Networking in iOS 225
URLSession 226
URLSessionConfiguration 226
URLRequest 227
URLSessionTask 227
Networking in Books 228
Process Overview 228
Modularization process 229
Identify the Class’s Responsibilities 229
Design Overview 229
NetworkLayer Tasks to Be Refactored 230
NetworkLayer New Design 230
Kickoff 231
Verification Tests 231
Make a Network Request 231
RequestProtocol 233
Execute Request 236
Mocking URLSession 237
Using URLSession 241
Showcasing Test Value 242
Handle a Failing Request 242
Putting It All Together 246
Exercise 252
Summary 252
Chapter 10: Taming Core Data 254
The Core Data Stack 255
Managed Object Model 256
Persistent Store Coordinator 257
Persistent Store 257
Managed Object Context 258
Persistent Container 258
Core Data in Books 259
Testing Stack 259
CoreDataManager 260
CoreDataStack 262
Inject the Stack into CoreDataManager 271
TestEntity 273
Creation 274
Introducing Storable 275
Creation Implementation 276
Saving Changes 277
Fetching 279
Updating 281
Advanced Fetching 283
Next Steps 286
Putting It All Together 292
Exercise 294
Summary 294
Chapter 11: Adding Features to a Legacy App 296
Legacy Code Disclaimer 297
A/B Testing 297
New Feature 298
Kickoff 299
UI Tests 300
Integration Tests 303
Unit Tests and Actual Implementation 306
BookViewModel 306
BookViewPresenter 313
Final Steps 319
Summary 319
Chapter 12: Handling Production Issues 320
Our Tool 320
Integration 321
Production Bug 322
Debugging 322
UI Test 323
Unit Tests 324
Production Crash 328
Debugging 329
UI Test 332
Handle A/B Testing 334
Fixing Our Test 335
Summary 336
Index 337
About the Authors 13
About the Technical Reviewer 14
Acknowledgments 15
Chapter 1: TDD Basics 16
Types of Testing 17
Trouble with Automated Testing 18
TDD in a Nutshell 18
Why Use TDD? 20
External and Internal Quality 21
When to Use TDD? 22
When Not to Use TDD? 23
Refactoring 23
Modularization 23
Test Structure 24
Let’s TDD 24
Maximum Out of TDD 28
Exercise 31
Summary 32
Chapter 2: Unit Tests 34
Your First Test 34
What Do We Want to Test? 35
Creating a Unit Test Target 36
Adding a Test Case Class 38
Assert Methods 40
Assert Method Types 43
Truthfulness Asserts 43
Equality Asserts 43
Nullability Asserts 44
Comparison Asserts 46
Errors Asserts 47
Expectations 48
Expectation Types 50
Test Ordering 51
Randomized Ordering 53
Code Coverage 54
Exercise 56
Summary 57
Chapter 3: UI Tests 59
Your First Test 59
XCUITest Components 63
Our Chapter Goal 64
First Test Case 64
Launching the App 64
Querying the UI 65
Relationships 65
Interacting with the UI 68
UI Events 70
Assertions 70
Value Assertion 71
Accessibility 71
Accessibility Tips 73
Putting It All Together 75
Improve UI Tests 76
Exercise 77
Summary 77
Chapter 4: Testing Pyramid 79
Our App 80
UI Tests 81
Integration Tests 84
Unit Tests 91
Summary 95
Chapter 5: TDD Deep Dive 98
CoffeePot 98
Eye on the Big Picture 99
Requirements 100
Testing Pyramid 102
First Story 103
Architecture 104
MVP 105
First Integration Test 106
Unit Tests 109
CoffeeDrinksDataSource 109
CoffeeDrinksModelTests 111
CoffeeDrinksPresenterTests 115
Test Health Check 120
Second Story 122
Architecture 124
Exercise 129
Summary 129
Chapter 6: Modularization for the Win 131
Why Bother with Modularization? 131
What Is a Module? 134
Modularizing Your App 138
Introducing Books 140
Modularization Process 143
Initial Module Map 144
Choose a Class as a Starting Point 145
Identify the Class’s Responsibilities 146
Refactor Responsibilities 147
Verification Tests 148
Refactoring 149
Integration Test 151
NetworkLayer 153
MainViewModel 154
MainViewPresenter 158
Last Touches 161
Test Value 162
Rerun Verification Tests 163
Refactor the Rest of the Responsibilities 164
Next Starting Point 165
Exercise 165
Summary 165
Chapter 7: Dependency Injection and Mocks 168
Stubbing 168
Mocking 171
Test Doubles Creation 174
Creation Using Inheritance 174
Creation Using Protocols 176
Dependency Injection 179
Initializer Injection 180
Property Injection 181
Stubbing the Network in UI Tests 182
Summary 191
Chapter 8: Avoiding Multithreading Nightmares 193
What Is Concurrency? 193
GCD 194
Queues 194
Serial vs. Concurrent 195
Sync vs. Async 196
Cost of Concurrency 198
Reader-Writer Problem 200
Singleton Classes 200
Identifying a Race Condition 201
Applying TDD to the Problem 203
Thread Sanitizer 211
Make It Pass 213
Fixing Threading Issues in Books 215
Applying TDD 217
Summary 220
Chapter 9: Testing Your Network 222
Networking ABCs 222
HTTP Requests 223
HTTP Responses 223
URL 224
Networking in iOS 225
URLSession 226
URLSessionConfiguration 226
URLRequest 227
URLSessionTask 227
Networking in Books 228
Process Overview 228
Modularization process 229
Identify the Class’s Responsibilities 229
Design Overview 229
NetworkLayer Tasks to Be Refactored 230
NetworkLayer New Design 230
Kickoff 231
Verification Tests 231
Make a Network Request 231
RequestProtocol 233
Execute Request 236
Mocking URLSession 237
Using URLSession 241
Showcasing Test Value 242
Handle a Failing Request 242
Putting It All Together 246
Exercise 252
Summary 252
Chapter 10: Taming Core Data 254
The Core Data Stack 255
Managed Object Model 256
Persistent Store Coordinator 257
Persistent Store 257
Managed Object Context 258
Persistent Container 258
Core Data in Books 259
Testing Stack 259
CoreDataManager 260
CoreDataStack 262
Inject the Stack into CoreDataManager 271
TestEntity 273
Creation 274
Introducing Storable 275
Creation Implementation 276
Saving Changes 277
Fetching 279
Updating 281
Advanced Fetching 283
Next Steps 286
Putting It All Together 292
Exercise 294
Summary 294
Chapter 11: Adding Features to a Legacy App 296
Legacy Code Disclaimer 297
A/B Testing 297
New Feature 298
Kickoff 299
UI Tests 300
Integration Tests 303
Unit Tests and Actual Implementation 306
BookViewModel 306
BookViewPresenter 313
Final Steps 319
Summary 319
Chapter 12: Handling Production Issues 320
Our Tool 320
Integration 321
Production Bug 322
Debugging 322
UI Test 323
Unit Tests 324
Production Crash 328
Debugging 329
UI Test 332
Handle A/B Testing 334
Fixing Our Test 335
Summary 336
Index 337
备用描述
Improve current or new projects with top notch testability and maintainability. Writing tests improves the design of your apps, as it pushes you to have a more modularized design. This in turn improves the maintainability and sustainability of your apps. This book is for iOS developers who already know the basics of iOS and Swift development but want to learn all the testing pro features in iOS. You'll start by reviewing the TDD Cycle and how to implement these concepts on a legacy project or a new one. You'll then walk through TDD step-by-step on a blank project, including setting up test targets, assertions, and expectations. You'll follow that with all levels of testing such as unit tests, integration tests, and end-to-end tests, and also tackle fairly complex, yet badly written legacy code. The book will take you through the journey of modularizing a legacy app using TDD. Throughout this journey, you will be introduced to multiple testing concepts and techniques, like writing tests for network and core data layers. You will write tests to ensure the thread safety of your app. And you’ll add a new feature while you are in the middle of refactoring, which is an important skill so you can keep adding features while you are fixing your technical debt. By the end of this book, you will have all the tools needed to become a testing master. What You'll Learn Use mocking and dependency injection to make components more testable Write tests for asynchronous code like network code Add new features to existing legacy apps using TDD Who This Book Is For Experienced iOS developers who care about software quality and meeting customer expectations.
备用描述
Improve current or new projects with top notch testability and maintainability. Writing tests improves the design of your apps, as it pushes you to have a more modularized design. This in turn improves the maintainability and sustainability of your apps. This book is for iOS developers who already know the basics of iOS and Swift development but want to learn all the testing pro features in iOS. You'll start by reviewing the TDD Cycle and how to implement these concepts on a legacy project or a new one. You'll then walk through TDD step-by-step on a blank project, including setting up test targets, assertions, and expectations. You'll follow that with all levels of testing such as unit tests, integration tests, and end-to-end tests, and also tackle fairly complex, yet badly written legacy code. The book will take you through the journey of modularizing a legacy app using TDD. Throughout this journey, you will be introduced to multiple testing concepts and techniques, like writing tests for network and core data layers. You will write tests to ensure the thread safety of your app. And you'll add a new feature while you are in the middle of refactoring, which is an important skill so you can keep adding features while you are fixing your technical debt. By the end of this book, you will have all the tools needed to become a testing master. You will: Use mocking and dependency injection to make components more testable Write tests for asynchronous code like network code Add new features to existing legacy apps using TDD
备用描述
"Improve current or new projects with top notch testability and maintainability. Writing tests improves the design of your apps, as it pushes you to have a more modularized design. This in turn improves the maintainability and sustainability of your apps. This book is for iOS developers who already know the basics of iOS and Swift development but want to learn all the testing pro features in iOS. You'll start by reviewing the TDD Cycle and how to implement these concepts on a legacy project or a new one. You'll then walk through TDD step-by-step on a blank project, including setting up test targets, assertions, and expectations. You'll follow that with all levels of testing such as unit tests, integration tests, and end-to-end tests, and also tackle fairly complex, yet badly written legacy code. The book will take you through the journey of modularizing a legacy app using TDD. Throughout this journey, you will be introduced to multiple testing concepts and techniques, like writing tests for network and core data layers. You will write tests to ensure the thread safety of your app. And you'll add a new feature while you are in the middle of refactoring, which is an important skill so you can keep adding features while you are fixing your technical debt. By the end of this book, you will have all the tools needed to become a testing master."--Amazon.ca
开源日期
2022-04-08
🚀 快速下载
成为会员以支持书籍、论文等的长期保存。为了感谢您对我们的支持,您将获得高速下载权益。❤️
🐢 低速下载
由可信的合作方提供。 更多信息请参见常见问题解答。 (可能需要验证浏览器——无限次下载!)
- 低速服务器(合作方提供) #1 (稍快但需要排队)
- 低速服务器(合作方提供) #2 (稍快但需要排队)
- 低速服务器(合作方提供) #3 (稍快但需要排队)
- 低速服务器(合作方提供) #4 (稍快但需要排队)
- 低速服务器(合作方提供) #5 (无需排队,但可能非常慢)
- 低速服务器(合作方提供) #6 (无需排队,但可能非常慢)
- 低速服务器(合作方提供) #7 (无需排队,但可能非常慢)
- 低速服务器(合作方提供) #8 (无需排队,但可能非常慢)
- 低速服务器(合作方提供) #9 (无需排队,但可能非常慢)
- 下载后: 在我们的查看器中打开
所有选项下载的文件都相同,应该可以安全使用。即使这样,从互联网下载文件时始终要小心。例如,确保您的设备更新及时。
外部下载
-
对于大文件,我们建议使用下载管理器以防止中断。
推荐的下载管理器:JDownloader -
您将需要一个电子书或 PDF 阅读器来打开文件,具体取决于文件格式。
推荐的电子书阅读器:Anna的档案在线查看器、ReadEra和Calibre -
使用在线工具进行格式转换。
推荐的转换工具:CloudConvert和PrintFriendly -
您可以将 PDF 和 EPUB 文件发送到您的 Kindle 或 Kobo 电子阅读器。
推荐的工具:亚马逊的“发送到 Kindle”和djazz 的“发送到 Kobo/Kindle” -
支持作者和图书馆
✍️ 如果您喜欢这个并且能够负担得起,请考虑购买原版,或直接支持作者。
📚 如果您当地的图书馆有这本书,请考虑在那里免费借阅。
下面的文字仅以英文继续。
总下载量:
“文件的MD5”是根据文件内容计算出的哈希值,并且基于该内容具有相当的唯一性。我们这里索引的所有影子图书馆都主要使用MD5来标识文件。
一个文件可能会出现在多个影子图书馆中。有关我们编译的各种数据集的信息,请参见数据集页面。
有关此文件的详细信息,请查看其JSON 文件。 Live/debug JSON version. Live/debug page.