𝔖 Scriptorium
✦   LIBER   ✦

📁

Test-Driven Development in Swift: Compile Better Code with XCTest and TDD

✍ Scribed by Gio Lodi


Publisher
Apress
Year
2021
Tongue
English
Leaves
296
Edition
1
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Leverage Swift to practice effective and efficient test-driven development (TDD) methodology. Software testing and TDD are evergreen programming concepts―yet Swift developers haven't widely adopted them. What's needed is a clear roadmap to learn and adopt TDD in the Swift world. Over the past years, Apple has invested in XCTest and Xcode's testing infrastructure, making testing a new top priority in their ecosystem. Open-source libraries such as Quick and Nimble have also reached maturity. The tools are there. This book will show you how to wield them. 

TDD has much more to offer than catching bugs. With this book, you’ll learn a philosophy for building software. TDD enables engineers to solve problems incrementally, writing only as much code as necessary. By decomposing big problems into small steps, you can move along at a fast pace, always making visible progress. 

Participate in the test-driven development journey by building a real iOS application and incorporating new concepts through each chapter. The book's concepts will emerge as you figure out ways to use tests to drive the solutions to the problems of each chapter. Through the TDD of a single application, you’ll be introduced to all the staples and advanced concepts of the craft, understand the trade offs each technique offers, and review an iterative process of software development. 

Test-Driven Development in Swift provides the path for a highly efficient way to make amazing apps.

What You'll Learn

  • Write tests that are easy to maintain
  • Look after an ever-growing test suite
  • Build a testing vocabulary that can be applied outside the Swift world
  • See how Swift programming enhances the TDD flow seen in dynamic languages 
  • Discover how compiler errors can provide the same helpful guidance as failing tests do

Who This Book Is For

Mid-level developers keen to write higher quality code and improve their workflows. Also, developers that have already been writing tests but feel they are not getting the most out of them. 

✦ Table of Contents


Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
A Gift for You
Chapter 1: Why Test-Driven Development?
What Is a Test?
Manual Testing Is Inefficient
Code That Checks Other Code
From Writing Tests to Writing Tests First
From Writing Tests First to Test-Driven Development
Key Takeaways
Endnote
Chapter 2: XCTest Introduction
The Xcode Unit Test Target
XCTestCase and Equality Assertion
Other Assertions
Unwrapping Optionals
Expectations for Asynchronous Code
XCTestCase Life Cycle
Key Takeaways
Chapter 3: Getting Started with Test-Driven Development
Test List
Fake It…Till You Make It
Arrange, Act, Assert
First Make the Test Pass; then Make the Code Clean
The Compiler Is Part of the TDD Process
Wishful Coding
Key Takeaways
Chapter 4: Test-Driven Development in the Real World
The Menu Ordering App
Where to Begin?
Partition Problem and Solve Sequentially
Building the Menu
Use the Strictest Assertions Possible
Use the Clearest Assertion Possible
Don’t Let the Tests Crash
Test Naming Conventions
Red, Green, and Don’t Forget Refactor
Wiring Up the UI
Pure Functions
Key Takeaways
Chapter 5: Changing Tests with Fixtures
The Hidden Cost of Source Changes
Fixtures
Fixtures vs. Convenience Initializers
Fixtures Make the Test Actors Explicit
Fixtures Are Composable
Introduce Fixtures As Early As Possible
Practice Time
Key Takeaways
Endnote
Chapter 6: Testing Static SwiftUI Views
The Problem with Presentation Logic in the View
Decouple Presentation Logic from the View Implementation
Preparatory Refactor: Reduce the Working Surface Area
ViewModel
Using the ViewModel in the View
Beyond Testability
ViewModels Everywhere!
Key Takeaways
Endnotes
Chapter 7: Testing Dynamic SwiftUI Views
How SwiftUI and Combine Make Seamless View Updates Possible
Make the ViewModel Stream Updates with ObservableObject
The Dependency Inversion Principle
Decouple the ViewModel from the Data Fetching with DIP
How to Test Async Updates of @Published Properties
Mystery Guest
Practice Time
Key Takeaways
Chapter 8: Testing Code Based on Indirect Inputs
The Stub Test Double
Make Error Handling Explicit with Result
Practice Time
Key Takeaways
Chapter 9: Testing JSON Decoding
Option 1: Inline Strings
Option 2: JSON Files
Which Option to Choose?
Is Testing JSON Decoding Worth It?
Practice Time
Key Takeaways
Endnote
Chapter 10: Testing Network Code
Why You Shouldn’t Make Network Requests in Your Unit Tests
How to Decouple the Unit Tests from the Network
Simulate Network Requests Using a Stub
A Third-Party Alternative
Practice Time
Key Takeaways
Endnote
Chapter 11: Injecting Dependencies with  @EnvironmentObject
How Dependency Injection Keeps Each Test Isolated
Dependency Injection vs. Directly Accessing Shared Instances
Dependency Injection with @EnvironmentObject
The Downside of @EnvironmentObject
@EnvironmentObject vs. Directly Accessing Shared Instances
Practice Time
Key Takeaways
Chapter 12: Testing Side Effects
Third-Party Dependencies Are the Same As All Dependencies
The Benefit of Abstracting Third-Party Dependencies
Build Wrappers for Third-Party Dependencies
The Spy Test Double
The Downside of Using Spies
Practice Time
Key Takeaways
Chapter 13: Testing a Conditional View Presentation
Informing the User of the Checkout Completion
How to Test Asynchronous Code When There Is No Callback
Wiring Up the View
Testing the Alert Dismiss Behavior
Key Takeaways
Chapter 14: Fixing Bugs and Changing Existing Code with TDD
Fixing Bugs Driven by Tests
Changing Existing Code Driven by Tests
Key Takeaways
Chapter 15: Keeping Tests Isolated with Fakes and Clear with Dummies
Fake: How to Bypass Slow or Stateful Dependencies
Dummy: How to Provide Dependencies That Are Required but Irrelevant for the Behavior Being Tested
Key Takeaways
Chapter 16: Conclusion
More Than Just Testing
TDD and Software Design
TDD and Productivity
TDD and Product Development
Endnote
Cheatsheet
XCTest Test Structure
How to Test Asynchronous Code
How to Test Asynchronous Code When There Is No Callback
How to Test Combine Publishers
How to Test Changes to SwiftUI @Published Properties
Fixture Extension
Stub Test Double
Spy Test Double
Fake Test Double
Dummy Test Double
Appendix A: Where to Go from Here
Continuous Integration
Snapshot Testing
UI Testing
API Integration Testing
Use Modularization to Tame Long Build Times
How to Convince Your Team to Adopt TDD
Appendix B: Testing with Quick and Nimble
Nimble
Quick
Appendix C: TDD with UIKit
How to Unit Test a UIViewController
How to Test Table Views
How to Test ViewController Navigation and Presentation
What About AppKit and WatchKit?
Index


📜 SIMILAR VOLUMES


Test-Driven Development in Swift: Compil
✍ Gio Lodi 📂 Library 📅 2021 🏛 Apress 🌐 English

<p>Leverage Swift to practice effective and efficient test-driven development (TDD) methodology. Software testing and TDD are evergreen programming concepts―yet Swift developers haven't widely adopted them. What's needed is a clear roadmap to learn and adopt TDD in the Swift world. Over the past yea

iOS Code Testing: Test-Driven Developmen
✍ Abhishek Mishra 📂 Library 📅 2017 🏛 Apress 🌐 English

Put into motion practical examples to master Test-Driven Development (TDD) and acceptance testing in Swift. This book uses a pragmatic approach to writing well-tested code and provides techniques that can be used to retrofit tests to legacy code bases. You'll be introduced to basic principles of

Test-Driven iOS Development with Swift:
✍ Dr. Dominik Hauser 📂 Library 📅 2022 🏛 Packt Publishing 🌐 English

<p><span>Build robust applications using TDD with Swift 5.5 and become a TDD expert by writing tests for view controller, views, network code, and even SwiftUI view</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Build a complete iOS app using test-driven development</span></span></l

Test-Driven iOS Development with Swift:
✍ Dr. Dominik Hauser 📂 Library 📅 2022 🏛 Packt Publishing 🌐 English

<p><span>Build robust applications using TDD with Swift 5.5 and become a TDD expert by writing tests for view controller, views, network code, and even SwiftUI view</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Build a complete iOS app using test-driven development</span></span></l

Modern C++ programming with test-driven
✍ Jeff Langr 📂 Library 📅 2013 🏛 Pragmatic Bookshelf 🌐 English

If you program in C++ youve been neglected. Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to change your software to meet changing needs. But C++ progr