ForgetMeNotDemo unit tests
To get started, we examine one ViewModel at a time, paying attention to the methods. We do this because what we want to test is the business logic, and if you’ve done it right, most of your business logic will be in a ViewModel
class.
For example, turning our attention to PreferencesViewModel
, we see the Init()
method. The job of Init
is to populate the PreferenceList
collection. For now, we’ll ignore how it does this and just write a test to ensure that it does.
Implementing the triple-A pattern
Before we start, create an interface for PreferenceService
, as described earlier in the book (open PreferenceService
, right-click on the class name, and choose Extract Interface).
A classic design pattern for unit tests is the Arrange, Act, Assert (AAA) pattern. That is, you set up your test (Arrange), then you call a method or two (Act), and then check to make sure you have the expected results (Assert). Let’s see this in action...