In this video, Mark DiFranco writes unit tests for the sample project's location provider class in Xcode. 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] Next, we can add a test case…for the location provider.…Under our speedometer test group,…in the location group,…let's add a new file.…We'll select the unit test case class and click next.…We can name the tests…SPD location provider tests…and then click next.…Then we'll add it to this group.…Once again, we can clear out every method…except for the setup method…and we can remove this comment as well.…
At the top, let's testable import our speedometer target.…Our SUT for this class…will be the SPD location provider…so let's make that variable now.…Remember to make it implicitly unwrapped.…We can then add our DOCs.…The first one will be the location manager.…We'll name it location manager mock.…
The SPD location provider…also uses the location authorization…so we'll need a mock for that as well.…That type will be SPD location authorization mock.…Finally, we'll have to add a mock consumer.…This way we can test that the location provider…is passing on locations to the consumers.…
We'll make it an SPD location consumer mock.…
- 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.