Test-Driven Development in Swift with SwiftUI and Combine cover

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 skills

Charlie 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.

Subscribe for updates and bonus material.

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

  1. Why Test-Driven Development?
  2. XCTest Introduction
  3. Getting started with TDD
  4. TDD in the real world
  5. Changing Tests with Fixtures
  6. Testing Static SwiftUI Views
  7. Testing Dynamic SwiftUI Views
  8. Testing Code Based on Indirect Inputs
  9. Testing JSON Decoding
  10. Testing Networking Code
  11. Injecting Dependencies with @EnvironmentObject
  12. Testing Side Effects
  13. Testing Views Conditional Presentation
  14. Fixing Bugs and Changing Existing Code with TDD
  15. Keeping Tests Isolated and Clear with Fakes and Dummies
  16. Conclusion: More Than Just Testing
  17. Appendix: Quick & Nimble
  18. Appendix: Where to go from here
  19. Appendix: Testing UIKit code

About the Author

A picture of Gio.

Ciao! I’m Gio. For the past decade, I’ve been obsessed with software testing, automation, and Test-Driven Development. Since 2015, I’ve been sharing ideas on testing on my blog and with my talks. I’ve collected everything I learned along the way in this book.


  • 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 hello@tddinswift.com. Thanks!

Have a question? Shoot me an email at hello@tddinswift.com or get in touch on Twitter at @mokagio.

Subscribe for updates and bonus material.