MSTest Setup Environment Tutorial: In 3 Easy Steps
Tags: webdev, beginners, programming, tutorial
Published: 2023-04-12 07:05:19

MSTest setup is a popular open-source test framework that is shipped along with the Visual Studio IDE. It is also referred to as Visual Studio Unit Testing Framework. However, MSTest Setup is more synonymous within the developer community.

As the MSTest framework comes pre-bundled with Visual Studio, many developers prefer MSTest over other C# frameworks such as NUnit, xUnit.net, etc. for [test automation](https://www.lambdatest.com/selenium-automation?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=webpage). The latest version of MSTest is 2, a major overhaul over its predecessor. The earlier version of MSTest i.e. MSTest V1 was not open-source and lacked many good features (particularly parallel test execution) which were supported by other [Selenium C# testing frameworks](https://www.lambdatest.com/blog/top-selenium-csharp-framework/?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=blog).

MSTest V2 is cross-platform compatible, extensible, and supports parallel test execution which is one of the major requirements for performing Selenium C# testing. It also supports data-driven testing as methods can be executed multiple times by providing different input arguments. The MSTest framework recognizes the test via annotations/attributes under which the test code is present. [TestInitialize], [TestMethod], [TestCleanup] are the most widely used attributes by developers who make use of the [MSTest framework for automation testing.](https://www.lambdatest.com/selenium-automation-testing-with-MSTest?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=webpage)

In this MSTest setup tutorial, I’ll take a detailed look at setting up the MSTest framework which can help you get started with MSTest on Visual Studio.

**_A comprehensive end to end Testing tutorial that covers what [E2E Testing](https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=learning_hub) is, its importance, benefits, and how to perform it with real-time examples._**

## MSTest Setup Visual Studio For Development and Testing

Before moving ahead in this MSTest tutorial for environment setup, I’ll quickly address how to set up Visual Studio IDE for MSTest test case development. Shown below are the steps for installing Visual Studio 2019 (VS 2019):

### Download The Latest Visual Studio

Download the latest version of Visual Studio i.e. Visual Studio 2019. You can choose from either Professional/Community/Edition of Visual Studio. The selection should be based on your project requirements. In this MSTest tutorial for environment setup, I’m using the Community Edition of VS 2019.

![](https://cdn-images-1.medium.com/max/2000/0*ZbkAkJQ-68Ro103D.png)

### Install Necessary Platform For Development & Testing

In this MSTest tutorial for environment setup, the MSTest framework will be used for testing so we’ll be installing the necessary packages for development on the Windows platform.

![](https://cdn-images-1.medium.com/max/2562/0*9FSRn7hpCvHwaevb.png)

![](https://cdn-images-1.medium.com/max/2634/0*Yb19KW40WeNlFYOL.png)

### Sign-In To Visual Studio IDE

In order to leverage the features of Visual Studio 2019, it is recommended that you sign-in to the IDE so that you can make use of the useful features of Visual Studio 2019 such as pushing code to private Git repository, syncing settings, and more.

In the next section of the MSTest tutorial on environment setup, I’ll take a look at steps to be followed for the installation of the mandatory packages required for executing the tests based on the MSTest framework.

This MSTest Tutorial for beginners and professionals will help you learn how to use MSTest framework with Selenium C# for performing Selenium automation testing.

{% youtube 2XUQdN-Bi2o %}

## Installing The MSTest Framework & MSTest Adapter

For executing [automated browser testing](https://www.lambdatest.com/?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=webpage) using the MSTest framework, you need to install the corresponding test adapter as the adapter enables the execution of the test code. Installation of the MSTest adapter can be done by executing the package manager commands on the console or by accessing the package manager from the GUI. In this MSTest tutorial for environment setup, I’ll show you how to set up using both the options.

In order to install the required packages, we perform the following steps:

**Step 1:** Create a new project of the type ‘MSTest Test Project (.Net Core)’ in Visual Studio.

![](https://cdn-images-1.medium.com/max/2000/0*WQmwzRdBFhdhJ5tJ.png)

**Step 2:** Since the project is based on the MSTest framework, the default C# file that comes along with the project has attributes *[TestMethod]* and *[TestClass]* in it.

![](https://cdn-images-1.medium.com/max/2688/0*qEj85nSiKPaSP6MO.png)

Even if you have not created a MSTest Test Project, you could still make use of the MSTest framework by installing the framework using the NuGet Package Manager.

Take this certification to master the fundamentals of Selenium automation testing with C# and prove your credibility as a tester.

Here’s a short glimpse of the Selenium C# 101 certification from LambdaTest:
{% youtube ZU85Mjwgv54 %}

**_Automated [Functional Testing](https://www.lambdatest.com/blog/automated-functional-testing-what-it-is-how-it-helps/?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=blog) tests helps to ensure that your web app works as it was intented to. Learn more about functional tests, and how automating them can give you a faster release cycle._**

## Installing MSTest With NuGet Package

For installing the required MSTest packages for [cross browser testing](https://www.lambdatest.com/?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=webpage), you can either make use of the Package Manager commands or use the IDE to achieve the task. In case you are just getting started with Selenium C# testing using MSTest, I’ll recommend the IDE option.

### Using Visual Studio IDE To Install The MSTest Framework

To install the MSTest framework and the other mandatory packages for Selenium test automation with MSTest, perform the following steps using the Visual Studio IDE:

**Step 1:** Add Console.WriteLine(“Selenium C#”) to the newly created .cs file.

**Step 2:** Navigate to **Tools -> NuGet Package Manager -> Manager NuGet Packages** for Solution and search for the following packages in the Browse tab.

* MSTest.TestAdapter

* MSTest.TestFramework

* Microsoft.NET.Test.Sdk

![](https://cdn-images-1.medium.com/max/2000/0*iYzEEpGoYJ3q9Lid.png)

**Step 3:** Click on the **Install** button and press **OK** for each of these packages so that package is installed for the current project.

![](https://cdn-images-1.medium.com/max/2000/0*9OFKtql0bcF0QpC0.png)

### Using Package Manager Commands To Install The MSTest framework

Instead of using the IDE, the Package Manager (PM) commands can also be used for installing the required MSTest packages.

**Step 1:** For executing commands from the PM console, navigate to **Tools -> NuGet Package Manager -> Package Manager Console**.

![](https://cdn-images-1.medium.com/max/2000/0*mAfmgjvwOHQbnFXa.png)

**Step 2:** For installation of the packages, we use the Install-Package command with the required as the argument to the command.

    Install-Package MSTest.TestAdapter
    Install-Package MSTest.TestFramework
    Install-Package Microsoft.NET.Test.Sdk

Shown below is the installation screenshot:

![](https://cdn-images-1.medium.com/max/2000/0*N727-Gb_oDVVCAUK.png)

**Step 3:** You can confirm whether the packages are installed by executing the Get-Package command on Package Manager (PM) Console.

    PM> Get-Package
     
    Id                                  Versions
    --                                  --------
    MSTest.TestFramework                {2.0.0}
    MSTest.TestAdapter                  {2.0.0}
    coverlet.collector                  {1.0.1}
    Microsoft.NET.Test.Sdk              {16.2.0}

The version of MSTest framework is 2.0.0 or MSTest V2 which is currently the latest version of the MSTest framework.

**_Through this [usability testing](https://www.lambdatest.com/learning-hub/usability-testing?utm_source=devto&utm_medium=organic&utm_campaign=apr12_bh&utm_term=bh&utm_content=learning_hub) tutorial, you will learn how usability testing is a great way to discover unexpected bugs, find what is unnecessary or unused before going any further, and have unbiased opinions from an outsider._**

## Wrapping It Up

With this MSTest environment setup example, I demonstrated how to get started with the MSTest framework for Visual Studio. The steps listed in this MSTest tutorial for environment setup will help you in performing automation testing with C#.

That’s all for this MSTest tutorial on environment setup, I hope this cleared all your doubts with respect to the setup. In case of any further questions, please feel free to reach out to us in the comments section below. Help us to reach out to your peers and colleagues looking by retweeting us or sharing our posts on Social Media. **Happy Testing!!**?