Technically you’re an iOS developer, but you’re starting to feel more like a QA tester.

You cringe when you see the notification. Another bug report assigned to you.

You click back and forth between source files for hours trying to figure out what to do, knowing that if you don’t get this exactly right, something else will break and you won’t even know until you start seeing one-star reviews.

Eventually you decide to just try something, so you make a change to the code and run the app. It takes six taps just to get to the screen you need, then you have to type data into all eight text fields to test it. And that’s just the happy path; you’ll have to do it all again to test the error cases.

Given how unstable the codebase is, you wouldn’t be surprised to see another feature break, so once you’ve fixed the bug you’ll have to run a bunch of manual regression tests to make sure everything else still works. Sigh. Maybe tomorrow you’ll get to write some code.

Refactoring your massive view controllers seems like it would help, but the code is so brittle, you’re guaranteed to break something. And then you’d be back where you started — running tests instead of building features — when you’re already behind schedule.

What if you didn’t have to spend all your time testing brittle code?

Let’s consider another scenario…

Imagine being free to focus on doing what you do best: developing features your users will love.

You grin when you see the notification. Another five-star review!

After reading the entire review twice, you feel a new surge of motivation as you Command-Tab back to Xcode to finish building that new feature. Each time you develop a new component, you sit back and relax as your code automatically tests itself. When the tests pass, you’re confident that the feature you just built is stable and that the existing features still work the way they should.

You get the feature done a day ahead of schedule, and you’re confident that it’s solid — your automated tests are proof that it works exactly as it should.

You’ve been consistently able to ship new features much faster than before. Your safety net of automated tests has boosted your confidence, giving you the ability to quickly make changes to your code.

Whenever you notice a bit of code that needs to be cleaned up, you take a few minutes to refactor it, confident that it still works the way it should when you’re done. As a result of your frequent refactoring, your codebase is a joy to work with.

Free yourself of the burden of manual testing so you can ship solid features faster.

With a suite of unit tests that verifies your code quickly, frequently, and automatically, you can relieve yourself of the responsibility of manually testing everything. You’ll have more time to focus on building features, and you’ll be able to ship them faster when you’re confident that the changes you make don’t create bugs in the rest of the app. Every time your tests run, you’ll have proof that your code is stable and works the way it should.

And guess what? You don’t even need to spend the next six weeks rewriting your code and adding unit tests. Unit Testing in Swift will help you write your first tests in a few minutes and show you how to build up your test suite over time. You’ll be able to sit back and relax while your code tests itself, and you’ll be confident that it works correctly.

With Unit Testing in Swift, you’ll:

    • automate your testing process one requirement at a time so you don’t have to waste precious development time verifying everything manually
    • catch bugs before anyone else sees them by establishing good automated testing practices
    • speed up your debugging process by writing unit tests that’ll make it easier to find and fix bugs
    • build a regression test suite so you can avoid breaking features your users need
    • create a safety net for yourself so you can refactor spaghetti code with confidence

And you’ll have the peace of mind that comes from shipping an app you know is solid.

What’s in the book?

The book will guide you through setting up your Xcode project and writing unit tests for your view controllers, networking classes, JSON parser, and business logic. You’ll be able to add tests to your project as you go, and you’ll build confidence in your code each time you add another test that proves it works correctly.

  1. What are the benefits of unit testing?
  2. How to write your first unit tests
  3. Why test first, rather than test after?
  4. Practicing TDD: Red, Green, Refactor
  5. Validating text entry in a view controller
  6. What types of requirements should you test manually?
  7. Verifying your code automatically with continuous integration
  8. Testing the collection view
  9. Testing REST API requests
  10. Mocking the URLSession API
  11. Testing asynchronous code using XCTestExpectation
  12. Testing the JSON parser
  13. Mocking the JSON parser
  14. Stubbing the API client
  15. Mocking the image API request
  16. Growing your unit test suite
  17. Increasing your confidence with test coverage
  18. Mastering the art of unit testing
  19. Good testing practices

The Expanded Edition

  • PDF of Unit Testing in Swift
  • The tests and source code for the Top Movies app so you can see how to apply the concepts in the book to your own project
  • Video: Faking UserDefaults, where you’ll learn how to test UserDefaults without unwanted side effects
  • Video: How to refactor your Swift code using TDD, which will show you how to refactor legacy code by writing tests first so you can be sure it works

With the source code for the Top Movies app, you’ll be able to copy and paste unit tests into your own project to start building your automated test suite right away. The video will guide you through adding tests to an existing app as you refactor — and you’ll end up with cleaner code, confident that it works correctly.

Start Unit Testing in Swift today. Get the Expanded Edition for $69

Want to share with your team?

Get a team license and share the book, source code, and video — everything in the Expanded Edition — with up to 10 people so your entire team can be more productive.

Purchase a team license for $349

The Basic Edition

  • PDF of Unit Testing in Swift

If you’re confident you can implement the concepts in the book on your own, this edition is for you.

Start Unit Testing in Swift today. Get the Basic Edition for $39

What are people saying?

“50 pages in. Such a great introduction to TDD within iOS… would love to stay up late and plow through! Can you believe it, writing tests eagerly before bed.” — Pete Malone

  • “This is my first time writing unit tests and following TDD. So far I’ve learn’t how to start the VC life cycle so that I can access my IBOutlets. I’ve written 2 tests so far on an app I’m working on based on the first 2 chapters from your book.” — Mohit Athwani

“Your CI chapter is coming in handy since I’m setting it up for a client. It was so nice to have a question and immediately realize I have a book that covers it.” — Christina Moulton

Can I try a free sample?

Absolutely you can! Grab your free sample below and start Unit Testing in Swift today.

What format does the book come in?

You can download Unit Testing in Swift as a PDF.

If I buy the Basic Edition now, can I upgrade later for the difference?

Yes! Send me an email and I’ll help you upgrade to the edition you want.

What if I’m not happy with the book?

I want you to be happy with it, so if for some reason you’re not, just send me an email and I’ll give you a refund as soon as I can.

Who’s the author?

Hi, I’m Josh Brown. I’ve been writing unit tests for the last ten years. A couple years ago, I wrote Parsing JSON in Swift to teach people how to — you guessed it — parse JSON in Swift. I’ve been developing iOS apps for our clients — from trucking apps to food logging apps to contact management apps and more — since 2009. Most recently, I’ve been helping my coworkers start unit testing and writing everything I can about it. I hope this book makes it easier for you to get started.

I have another question.

Send it my way and I’d be happy to answer it.