Setting up a test project
To be able to do tests, we need a test project:
- To install the bUnit templates, open PowerShell and run the following command:
dotnet new --install bunit.template
- Make sure to check which is the current latest version of the templates on the bUnit web page: https://bunit.egilhansen.com/.
- In Visual Studio, right-click MyBlogSolution and choose Add | New Project.
- Search for
bUnit
and select bUnit Test Project in the results, and then click Next. Sometimes it takes time to find a template. We can also change the project type dropdown to bUnit to find the template. We might need to reboot Visual Studio to find it. - Name the project
MyBlog.Shared.Tests
, leave the location as is, and click Next. - Select .NET 5 in the dropdown.
Great! We now have a test project.
Before we go into mocking the API, let's take a look at the different methods available to us so we can get a feel for how bUnit works.
In MyBlog.Shared.Tests
,...