Course info
May 17, 2017
1h 41m

Everyone wants robust, bug-free apps. But constantly, manually going through use cases every time something changes in your code is an efficient method of ensuring you have a reliable application. That's where UI and unit testing comes in. In this course, Swift iOS UI and Unit Testing, you'll learn how to create UI and unit tests for Swift iOS apps. First, you'll discover how to set up UI and unit tests in your project. Next, you'll explore how to modify the UI and unit tests. Then, you'll identify what areas to test. Finally, you'll learn how to unit test the UI through ViewController methods. By the end of this course, you'll understand when to use UI vs. unit tests and how to create each.

About the author
About the author

Brett Romero is Founder of Bitesize Business School, author of three books and seven iOS applications.

More from the author
More courses by Brett Romero
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Brett Romero, and welcome to my course, Swift iOS UI and Unit Testing. I'm a software developer and a writer at Bitesize Business School. In this course, we're going to learn how to create UI and unit tests for Swift iOS apps. Testing is an area that many developers neglect, and it can show in buggy software that provides for a poor user experience. If you wanted to create a reliable app and save lots of time doing it, testing is the way to go. Some of the major topics that we're going to cover include setting up UI and unit tests in your project, modifying UI and unit tests, identifying areas to test, and unit testing the UI through ViewController methods. A popular topic, but difficult to achieve. By the end of this course, you'll understand when to use UI versus unit tests and how to create each. As well, you'll know how to discover areas that need testing in your app. Before beginning this course, you should be familiar with Swift. I hope you'll join me in this journey to learn UI and unit testing with the Swift iOS and Unit Testing course, at Pluralsight.

UI Testing
We're going to now get into UI testing, and I'd like to go over what we're going to cover in this particular module. So we're going to start out with simple tests. This is just going to get our feet wet, let us see how the mechanics of these tests work. Then we'll move into, how do you actually identify particular elements in the UI so that you can then latch onto them in your tests? Because you need to have some kind of title, some sort of identifying attribute of that UI element. So there's a tool we can use to help us with that. And we're going to look at XCTAssert, which allows a verification at the end of a test. It can be a comparison. It can be some kind of Boolean. There's actually a number of different things you can do, so we'll see how that works. And we're going to run a test, which is going to add a row and delete the same row. And we're going to see also, when you're using a test runner, you can run into different problems because sometimes it gets a little tripped up, but we'll also see how you can continue your test. You don't have to restart it. You can pick up where you left off. And in particular to this Delete scenario, we'll see also how sometimes a workflow can be difficult to execute while you're recording, and then how do you get around that? How do you eventually get to the final outcome you're looking for? So let's go ahead and get into this module.

Unit Testing Basics
Welcome to Unit Testing Basics. I want to give you an overview of what we're going to be covering in this module. So we're going to start with a simple unit test just to kind of get an understanding of the mechanics of how to create these unit tests. Then we'll move into the usefulness of setUp and tearDown functions, in particular how they apply to the application we're working with. Next, we'll get into a scenario where we need to validate several properties on an object, and that's going to require us to use several different asserts. Then we'll look at an area in our application that does not have test coverage and is also not even testable, and then how you can resolve that issue by making that particular code testable and creating the unit test for it. So let's go ahead and jump in.

Advanced Testing Techniques
In this module, we're going to go beyond the basics that we've been covering and get into some advanced topics to make our testing a little bit more efficient. I'd like to give you now an overview of what we're going to cover in this module. We're going to start with global variables and how they can be useful inside of our tests. Specifically, we're going to exploit the setUp and tearDown functions with these variables so we can be sure the variable is going to be initialized and destroyed for every test. Then we'll get into reusing of code, particularly how we can make use of it inside of functions. So what we're going to do is create functions that we can then use in our tests and actually have test functions we can use in other tests. Then we're going to look at test coverage, which is going to be how much of our code is actually getting coverage through our testing that we're doing. So we'll be able to identify various gaps using what's called the Report Navigator, and then see how to provide coverage to those gaps by creating tests for them. And we'll get into debugging our unit tests because sometimes you're going to want to know what exactly is going on in this test that I'm getting this particular result, because you might not understand why that's happening. So we're going to see how to do debugging of our tests. And then finally, getting to a TableView and testing the Delegate methods isn't really straight forward, so we're going to see how do you do something like that for whatever reason. And once you see how it's done for this particular UI component, you will know how to do it for some of the others since they follow a very similar pattern. So let's go ahead and get into this module.