🦔

How to add a test project to a solution in Visual Studio 2022

2024/05/16に公開

A note for me of frequently used steps when you create application.

Target

  • Unit test framework: MSTest
  • Mock framework: Moq

Steps

Add Test Project

1. Right click the solution and Add -> New Project

2. Search MSTest and Select, then click Next

3. Configure the project

4. Choose latest .NET runtime and create

Connect test project

5. Right click the test project and Add -> Project reference

6.Check the target project and click OK

  • Now you can access the target class or methods in the target project.

Install mock framework

7. Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution

  • Open NuGet package manager to install mocking tool

8. Move Browse tab, then Search Moq and check the test project. Click Install after confirming if the version is latest.

9. Click Apply

  • Now you can use Moq framework in your test code.

Discussion