Mark DiFranco creates mock classes for the classes in the sample project. Learn which classes need to be mocked, as well as some useful tips for making it easier to write tests.
- [Instructor] Now let's create some mock versions…of our classes.…We'll store the mock versions in the test target.…So we can close the group speedometer at the top…and open up speedometer tests.…We'll make a new group under this group, and we'll call…it mocks.…Once again, we'll open up the right panel and click…on the folder icon, and we'll create a new folder…for mocks.…
Let's first make a mock for the SPD location manager.…We'll create a new file in the mocks group.…We'll make it a swift file and click next.…And we'll name it SPDLocationManagerMock and then…we'll click create.…Now let's define a class and we'll…call it SPDLocationManagerMock.…We'll copy the name from the header here.…
We'll make it conform to our SPDLocationManager protocol.…Now we're getting an error here because this type…is not available in the test target.…In order to change that, we're going to have to import…our main target.…At the top, we'll add an import speedometer.…Since this type is internal, it's still not visible to us.…We can add an at testable to the start of the import.…
- 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.