Ensuring App Quality with Tests

In all chapters up to this one, we've mostly focused on writing code that's used in our apps. The apps we've built are small and can be tested manually, quite quickly. However, this approach doesn't scale well if your apps become larger. This approach also doesn't scale if you want to verify lots of different user input, lots of screens, complex logic, or even if you want to run tests on many different devices.

Xcode comes with built-in testing tools. These tools allow you to write tests so you can make sure that all of the business logic for your app works as expected. More importantly, you can test that your user interface works and behaves as intended in many different automated scenarios.

Many developers tend to shy away from testing, postpone it until the end of the project, or simply don't do it at all. The reason for this is often that it's pretty hard to figure out how to write proper tests if you just start out. For instance, many developers feel like large parts of testing are so obvious that writing tests feels silly. However, if not approached properly, tests can be more of a burden than a relief by being high-maintenance and not testing important areas.

This chapter aims to be an introduction to writing both logic and interface tests using Xcode and its built-in tools. By the end of this chapter, you should be able to set up a solid, basic suite of tests and understand how you can make use of the tools provided by both Xcode and Swift to write better code that is testable and reliable.

This chapter covers the following two topics:

Let's not waste any time and dive straight into the wonderful world of testing your app logic.