From the course: Swift: Writing Testable Code

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

What to mock

What to mock

- [Narrator] There are some issues to doing a test of the full system. We want to reduce the app's dependency on external systems. If our app makes a web request, we don't want the test to fail when the server is down or if the request takes too long. We want our UITest to be as predictable as possible. Luckily, because of how we've architected our app, we can easily mock out the unpredictable parts of our app. Since we want to test as much of our system as we can, it's best to mock out classes as low a level as possible. This allows the test to use as much of our code as possible. For instance if we were trying to mock up the app's web requests, we would create a mock of URLSession and not one of a higher level class. XCUITest provides an API for passing information to our app during UITests. So let's take a look at how we can use that to mock out classes in our project. In order to mock out certain classes during UITests, we're going to use something called launchArguments…

Contents