In this video, Mark DiFranco writes unit tests for the class that checks 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.
- Let's add some tests for our last class,…the SPD location speed checker class.…Under speedometer tests and location groups,…let's add a new file.…We'll make it a unit test case class.…Let's name it SPD location speed checker tests.…Then we can click next and create.…Once again, we can clear out all the methods except for…set up and remove this comment.…
At the top, let's testable import our speedometer target.…Our SUT in this case will be an SPD location speed checker.…Let's add the variable now.…Make sure to make it implicitly unwrapped.…We'll then add a mock for the location provider…of type SPDLocationProviderMock…and we'll add a delegate mock as well.…
That way we can make sure that the delegate…is called at the right times.…The type that we're looking for is…the SPDLocationSpeedCheckerDelegateMock.…In our set up, we can initialize our mocks.…We'll start with the location provider mock,…and we can do the delegate mock as well.…Then we can initialize our SUT,…remembering to use the default class,…so we use the actual implementation and…
- 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.