Test-Driven Development in Swift
with SwiftUI and Combine
Harness the power of unit testing to write clean code that works; fast and with confidence.
Structured in just the right way to help you grasp the complicated topic of Test-Driven Development. With detailed descriptions of concepts and ideas along side coding examples, it gives you everything you need to grow your testing skillsCharlie Scheer, iOS Developer @ Automattic
“I hate tapping through the app to verify my changes”
How many times did you make a simple change to your app, which took more time to verify than to write, launching the app on the Simulator and tapping your way through it to reach the code you just changed? What if there was a way to make sure every business logic change you implement works without manually triggering through the app?
With unit tests, you can verify your business logic behavior without manually stepping through the different screens of the app. Each test runs at a fraction of the time it takes to exercise the app through its UI.
If you’re unfamiliar with test-driven development, Test-Driven Development in Swift is a great introduction, building up one clear example at a time. If you are familiar with TDD, the book will teach you the testing toolkit you should be using in Swift.Adam Johnson, Python Testing Expert
“I’ve done the unit tests tutorials online, but I don’t know how to test real code”
Most unit testing tutorials use examples too simple compared to the real-world code we write every day. Who needs to implement a summation function?! That’s why the book teaches how to write tests and practice TDD to build a real-world application.
You’ll meet Alberto, an Italian restaurant owner in need of a custom-built menu ordering app. His simple yet realistic app requires networking, third-party SDKs, sharing state across multiple screens, and, of course, managing list views.
Table of Contents
- Why Test-Driven Development?
- XCTest Introduction
- Getting started with TDD
- TDD in the real world
- Changing Tests with Fixtures
- Testing Static SwiftUI Views
- Testing Dynamic SwiftUI Views
- Testing Code Based on Indirect Inputs
- Testing JSON Decoding
- Testing Networking Code
- Injecting Dependencies with
- Testing Side Effects
- Testing Views Conditional Presentation
- Fixing Bugs and Changing Existing Code with TDD
- Keeping Tests Isolated and Clear with Fakes and Dummies
- Conclusion: More Than Just Testing
- Appendix: Quick & Nimble
- Appendix: Where to go from here
- Appendix: Testing UIKit code
About the Author
- Where can I find the source code for the book? You can find all the code from the book on GitHub.
- I found at typo or issue, how can I report it? First, check out the Errata page to see if it’s there already, if not, get in touch at firstname.lastname@example.org. Thanks!
Have a question? Shoot me an email at email@example.com or get in touch on Twitter at @mokagio.