DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks

Trending

  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. MSTest Tutorial: Environment Setup For Selenium Testing

MSTest Tutorial: Environment Setup For Selenium Testing

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

Himanshu Sheth user avatar by
Himanshu Sheth
CORE ·
Jun. 26, 20 · Tutorial
Like (14)
Save
Tweet
Share
4.07K Views

Join the DZone community and get the full member experience.

Join For Free

MSTest 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 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 Selenium test automation. The latest version of MSTest is MSTest V2, it is 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.

let me try it

The latest version of the MSTest framework 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 one method 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.

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

Setting Up Visual Studio For MSTest Tutorial

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 from here. 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.

visual studio

Install Necessary Platform For Development and Testing

In this MSTest tutorial for environment setup, the framework will be used for testing hence, we install the necessary packages for development on the Windows platform.

studio installer

workloads

Sign-In To Visual Studio IDE

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.

Installing The MSTest Framework and MSTest Adapter

For executing automated browser testing 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.

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.

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.

TestMethod

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

Installing MSTest With NuGet Package

For installing the required MSTest packages for cross-browser testing, 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 -> Manage NuGet Packages for Solution and search for the following packages in the Browse tab.

  • MSTest.TestAdapter
  • MSTest.TestFramework
  • Microsoft.NET.Test.Sdk

package manager

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

test framework

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.

Step 2. For the installation of the packages, we use the Install-Package command with the required <package-names> as the argument to the command.

Java
 




xxxxxxxxxx
1


 
1
Install-Package MSTest.TestAdapter
2
Install-Package MSTest.TestFramework
3
Install-Package Microsoft.NET.Test.Sdk
4

          



Shown below is the installation screenshot:

package installer

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

C#
 




xxxxxxxxxx
1


 
1
PM> Get-Package
2
 
3
Id                                  Versions
4
--                                  --------
5
MSTest.TestFramework                {2.0.0}
6
MSTest.TestAdapter                  {2.0.0}
7
coverlet.collector                  {1.0.1}
8
Microsoft.NET.Test.Sdk              {16.2.0}
9

          



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

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#. For running your first test script with MSTest, you can refer to the article linked. I’ve also covered a complete series on Selenium C# tutorial, you might want to check it out as well. 

That’s all for this MSTest tutorial on environment setup, I hope this cleared all your doubts concerning 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!

Package manager Framework unit test

Published at DZone with permission of Himanshu Sheth. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Implementing a Serverless DevOps Pipeline With AWS Lambda and CodePipeline
  • Unlocking the Power of AIOps: Enhancing DevOps With Intelligent Automation for Optimized IT Operations
  • The SPACE Framework for Developer Productivity
  • Top 10 Pillars of Zero Trust Networks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: