Testing MAUI-specific code
As shown in the previous examples, the majority of our code can be tested independently of the platform. But let’s not forget that there is code in our MAUI project as well that could benefit from some unit tests.
Let’s start by adding a new project to hold our tests for the Recipes.Mobile
project:
- Add a new xUnit Test Project type, just as we did at the beginning of this chapter. Name this project
Recipes.Mobile.UnitTests
. - Once the project has been created, add a reference to the
Recipes.Mobile
project. - Add the AutoBogus NuGet package to this project.
The Recipes.Mobile.UnitTests
project doesn’t target any specific frameworks other than net8.0
. Because of that, we need to make sure net8.0
is on the list of target frameworks of the MAUI project as well. Also, we need to make sure that when the Recipes.Mobile
project targets this additional net8.0
framework, it doesn’t output an EXE file. Let’s see...