Learn how to use protocols when dealing with code you didn't write. Mark DiFranco uses Swift's extensions to extend external classes to conform to protocols of your choosing. Learn how to write these extensions in a way that guarantees you have maximum test coverage in your unit tests. Then, head over to the sample project to implement what you've learned.
- [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 allows us to keep our file structure…
- Why write unit tests?
- What is dependency injection?
- Using protocols to help with tests
- Handling external dependencies
- Anatomy of a test case
- Writing tests
- Analyzing code coverage
- Visualizing test results
- Writing and extending UI tests
Skill Level Intermediate
1. Dependency Injection
2. Using Protocols
3. Writing Tests
4. UI Tests
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.