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.

Handling external dependencies

Handling external dependencies

- [Instructor] Every app has external dependencies. These are the frameworks and APIs that our app uses, but we didn't implement ourselves or we don't have control over. Thanks to Swift's extensions we can extend an external class to conform to a protocol that we write. Once we've done that, it's trivial to mock out this external class in our tests. Doing so will also maximize the amount of code we can cover with our unit tests. Let's head over to the project and wrap an external class in a protocol. To get speed updates, we're going to use the CLLocationManager class. Therefore, we need to mock out this dependency and hide it behind a protocol. Let's start by creating a group for our location classes. We'll call it Location. Let's open up the right panel by clicking the button in the top right of Xcode, selecting the location group that we just made, and going to identity and type section and selecting the folder icon. Now we can create a new folder for the location group. This…

Contents