In this video, Mark DiFranco writes unit tests for the class that provides the user's speed in the sample project. Learn how to take advantage of the setup method to reset the state before each test. Take a look at some good habits to form when choosing which tests to write. Then, implement the tests, adhering to the formatting outlined in previous videos.
- [Instructor] Now let's add a test case…for the SPDLocationSpeedProvider.…On the right under the SpeedometerTests and Location group,…let's add a new file.…We'll select Unit Test Case Class…and we'll name it SPDLocationSpeedProviderTests.…We'll click Next…and we'll put it in the Location group.…Once again, we can remove everything…except for the setup method…and we can delete this comment as well.…
At the top, let's testable import our speedometer target.…This time, our sut is going to be an SPDLocationSpeedProvider.…We'll set up our first doc…as a mock of the location provider.…
Its type will be SPDLocationProviderMock.…Let's add a mock for the delegate as well.…The delegate type will be…SPDLocationSpeedProviderDelegateMock.…Now let's head over to the setup method.…We'll setup our docs and sut in the setup method…to ensure that the state gets reset…each time a test is run.…Let's initialize the locationProviderMock first.…
We'll use a default constructor.…We'll do the same for our delegate.…Let's update the name from delegate to delegateMock.…
- 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
Swift 3 Essential Training: Beyond the Basicswith Scott Gardner2h 58m 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.