Testing ViewModels

When unit testing ViewModels, it is best to break the tests into individual test classes that represent each ViewModel, resulting in a one-to-one relationship between ViewModel classes and the unit test classes that test their logic.

In order to test our ViewModels, we will need to add a reference to them within the unit tests project, as shown in the following screenshot:

We will start by creating a set of unit tests for DetailViewModel:

  1. First, create a new folder in the TripLog.Tests project named ViewModels. This helps keep the file structure of the tests the same as the library being tested.
  2. Next, create a new empty ...

Get Mastering Xamarin.Forms - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.