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.

Coming soon! – Subscribe to receive updates about the launch and bonus material.

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.

“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. Fixtures
  6. How to test static views
  7. How to test dynamic views
  8. How to test code depending on indirect inputs with Stubs
  9. How to test JSON decoding
  10. How to test networking code
  11. Dependency Injection with @EnvironmentObject
  12. How to test side effects with Spies
  13. How to test conditional view presentation
  14. How to fix bugs and change existing code with TDD
  15. How to keep tests isolated and clear with Fakes and Dummies
  16. Conclusion
  17. Where to go from here
  18. Appendix: Quick & Nimble
  19. Appendix: Testing UIKit code

Coming soon! – Subscribe to receive updates about the launch and bonus material.

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.

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