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
From the course: Swift: Writing Testable Code
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Using protocols to help with tests3m 2s
-
Handling external dependencies11m
-
Business logic: Overview1m 37s
-
Business logic: Authorization7m 5s
-
Business logic: Location provider7m
-
Business logic: Speed provider3m 33s
-
Business logic: Speed checker6m 15s
-
Using Swinject: Overview1m 5s
-
Using Swinject: Assemblies9m 26s
-
Using Swinject: Assembler6m 4s
-
Building the storyboard10m 34s
-
Building the view controller16m 4s
-
Using SwinjectStoryboard: Overview36s
-
Using SwinjectStoryboard: Demo5m 43s
-
-
-
-