Setting up a test project
To be able to run tests, we need a test project:
- To install the bUnit templates, open PowerShell and run the following command:
dotnet new install bunit.template
- Check which is the latest version of the templates on the bUnit web page: https://bunit.dev/.
- In Visual Studio, right-click the MyBlog solution and choose Add | New Project.
- Search for bUnit, select bUnit Test Project in the results, and then click Next. Sometimes, it takes time to find a template, and 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.Tests
, leave the location as is, and click Next. - Select xUnit as the unit test framework and target framework: .NET 8.0, and click Create.
Great! We now have a test project. Before we mock the API, let’s look at the different methods available to us so we can get a feel for how bUnit...