Creating unit tests
To get started, right-click on the solution and choose Add New Project. In the dialog box, use the dropdown to pick UnitTest. There are a number of unit test frameworks. The two most popular are the older NUnit and the newer xUnit. We’ll choose xUnit Test Project, as shown in Figure 9.1:
Figure 9.1 – Selecting the unit test type
- Click Next and fill in the name and location of your new project. Typically, the name will be the name of the solution followed by
.Tests
, as shown in the following figure:
Figure 9.2 – Naming the test project
- Click Next and select the .NET platform (this book will use .NET 7).
Visual Studio will create your project as well as the first unit test class and method. Since this is generic, delete that class and create one called PreferencesTests
.
Setting the project reference
Before doing anything else, we need to make ForgetMeNotDemo.Tests...