Category Archives: Visual Studio

Creating a test project in Visual Studio

Now let us try to understand how we can create a test project in Visual studio.

Open up Visual Studio and click on New project. In new project window, you have to select unit test project as shown in below image.

Unit testing project in Visual Studio
Unit testing project in Visual Studio

It will create a new test project as shown in below image.

Unit test project layout in Visual Studio
Unit test project layout in Visual Studio

As shown in above image, we have created a simple test method called as TestMethod1.

You can run unit tests in 3 ways.

  1. Right click on the method and run it.
  2. Using test explorer.
  3. Using command line – MSTest and VSTest.

Below image shows how to run tests from IDE.

Run tests in Visual Studio
Run tests in Visual Studio

Below image shows test explorer in visual studio.

Test explorer in Visual Studio
Test explorer in Visual Studio

To run tests using MSTest, you will have to use command as shown in below image.

Executing test using MSTest command line
Executing test using MSTest command line