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
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Observability Architecture: Financial Payments Introduction
  • Reactive Programming
  • Auditing Tools for Kubernetes

Trending

  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Observability Architecture: Financial Payments Introduction
  • Reactive Programming
  • Auditing Tools for Kubernetes
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. XUnit Testing Tutorial: Environment Setup For Selenium Testing

XUnit Testing Tutorial: Environment Setup For Selenium Testing

xUnit is a popular open-source testing framework created by the developers of NUnit. Learn how to set up xUnit with visual studio!

Himanshu Sheth user avatar by
Himanshu Sheth
CORE ·
Jun. 15, 20 · Tutorial
Like (13)
Save
Tweet
Share
4.72K Views

Join the DZone community and get the full member experience.

Join For Free

xUnit.net (also referred to as xUnit) framework is a popular open-source unit testing framework for the .Net platform. The framework is built with a community focus. Since there is a focus on the community, it is easier to expand upon than other popular Selenium test automation frameworks.

As xUnit is written by the creators of the NUnit framework, you would find a lot of similarities between the two frameworks. The intention of creating a new unit testing framework was to build a much better framework from ground-up.

Unlike other popular frameworks for automation testing with Selenium C#, like NUnit and MSTest, this test framework follows a more unique style of attributes/annotations. 

The xUnit framework has fewer attributes in comparison to the NUnit and MSTest frameworks. The other advantage of using xUnit is that the Selenium test automation framework creates a new instance of a test class for every test. At the time of writing this blog, the latest version of xUnit was 2.4.1.

In this xUnit testing tutorial, I’ll take a detailed look at setting up the xUnit framework (or xUnit setup example) which can help you get started with xUnit (or xUnit.net) on Visual Studio.

Setting Up Visual Studio For Development And Testing

For development, I’ll use the Visual Studio 2019 (VS 2019) IDE. Before looking into the xUnit setup example, I’ll take a brief look at setting up Visual Studio for automation testing with Selenium C#.

1. The latest version of Visual Studio 2019 can be downloaded from here. You can choose from the Community/Professional/Enterprise versions. In this xUnit testing tutorial, I have used the Community Edition of Visual Studio 2019.

visual studio 2019

2. In this xUnit testing tutorial, the xUnit test framework will be used along with Selenium for test automation. Hence, I’ll install the necessary packages that aid in automation testing with Selenium C# on the Windows platform.

visual studio installer

workloads

3. In case you are also installing the Community Edition of Visual Studio, it is important that you sign-in to the IDE else you would not be able to use the IDE after the trial period (approximately 30 days). Once you sign-in, you can also utilize other powerful features such as pushing source code to private Git, syncing Visual Studio settings, and more.

In the next section of the xUnit testing tutorial, I’ll take a look at the steps to install the mandatory packages for performing automation testing with Selenium C# using xUnit framework. If you want to know more about how to set up Selenium in Visual Studio, you can refer to this blog linked.

Installing The xUnit Framework and xUnit.net Runner

For executing tests that make use of the xUnit framework, you’ll have to install the corresponding test runner i.e. xUnit.net runner. Installation of the xUnit framework and its runner can be done by installing the packages using the package manager from GUI or executing the equivalent package manager (PM) commands on the terminal.

For this xUnit testing tutorial, I’ll explore both these options for installing the xUnit framework. Before the installation of the required packages, you’ll have to perform the following steps:

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

create new project

2. Since I have created the project based on the xUnit.net framework, the default .cs file contains the [Fact] attribute in it. Also, the xUnit package is included by default in the source code.

Unit local test

In case you have not created a project of the type mentioned above, you can still use the xUnit framework for performing automation testing with Selenium C#. The xUnit framework and the runner can be installed using the package manager from GUI or the terminal.

Using Visual Studio IDE

For installing the xUnit test framework and other required packages for performing Selenium test automation with xUnit, perform the following steps:

1. Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution for opening NuGet Package Manager in Visual Studio.

tools

2. Search for the following packages in the Browse tab and click Install

  • xunit
  • xunit.runner.visualstudio
  • Microsoft.NET.Test.Sdk

xunit

Using Package Manager (PM) Commands

If you are comfortable using the terminal, then you should look at the option of installing the xUnit framework using the Package Manager (PM) commands.

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

project manager

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

XML
 




x


 
1
Install-Package xunit
2
Install-Package xunit.runner.visualstudio
3
Install-Package Microsoft.NET.Test.Sdk
4

          



Shown below are the package installation snapshots:

install package

install package

To check whether the packages have been installed successfully, execute the Get-Package command on the PM console. Shown below is the execution output:

C#
 




xxxxxxxxxx
1


 
1
PM> Get-Package
2
 
3
Id                                  Versions
4
--                                  --------
5
xunit                               {2.4.1}
6
xunit.runner.visualstudio           {2.4.1}
7
Microsoft.NET.Test.Sdk              {16.2.0}
8

          



Wrapping It Up!

With this crisp xUnit setup example for Selenium test automation, I demonstrated how to get started with the xUnit (or xUnit.net) framework for Visual Studio. Steps shown in the xUnit testing tutorial will be instrumental in performing automation testing with Selenium C# frameworks.

This brings us to the conclusion of this article. You can go ahead and set up the xUnit environment for yourself. We’d have covered a lot of articles before on automation testing with Selenium C#, particularly I’ve covered a whole series on Selenium C# tutorial, you might want to check it out. Feel free to check them out, and do help us to reach out to more people by sharing and retweeting our article. That’s all folks.

Happy Testing!!!

Framework Package manager unit test

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

Opinions expressed by DZone contributors are their own.

Trending

  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Observability Architecture: Financial Payments Introduction
  • Reactive Programming
  • Auditing Tools for Kubernetes

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: