Mark DiFranco explains how Swift's protocols need to be used when writing tests. Learn some alternative ways of testing your classes, and explore some of the pitfalls you may encounter when using them. Then, learn how to apply protocols to solve the problem for good.
- [Narrator] At this point, we've seen that each…of our classes dependencies should be injected…into their initializers if we are to follow…the dependency inversion principal.…Doing this alone will work perfectly fine in your app.…But what about when we want to go write tests?…In this video, we'll take a look at typical problems…when mocking classes…and how protocols can help us solve them.…When writing unit tests, we want to isolate each class…in our app, control all the inputs to the class,…and assert that the outputs are exactly what we expect.…By inputs, I mean the collection of our classes…public methods, properties, and dependencies.…
The public methods and properties are easy to test…in a unit test.…We simply use them as we would in our app.…The issue arises when we try and control the dependencies…in the same way.…Let's take a look at a quick example…to illustrate the problem.…So here we have our PhotoDownloader class again…and we have the session and cache being created at the top.…Once we've created the PhotoDownloader class,…
- 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
Core Data for iOS and macOS Enterprise Developerswith Jon Bott1h 46m Intermediate
Learning Server-Side Swift with Vaporwith Ron Buencamino1h 30m 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.