Домой United States USA — software Most Complete MSTest Framework Tutorial Using. Net Core

Most Complete MSTest Framework Tutorial Using. Net Core

145
0
ПОДЕЛИТЬСЯ

Learn about the MSTest Framework using .Net Core in Selenium C# and the aspects related to cross browser testing and parallel testing in this MSTest tutorial.
Join the DZone community and get the full member experience. With the advent of programming languages like Python, Ruby on Rails, etc., there is thinking amongst the developer community that the C language is losing relevance. Strikingly, C is still considered a dominant programming language for system programming as it provides optimized machine instructions for any type of provided input. Not only C, the languages that are derived from C, i.e., C# and C++, are also embraced with arms wide open by the developer community. As far as unit testing/automation testing using C# is concerned, there are some frameworks like NUnit, xUnit. Net, MSTest Framework, etc., to save the day. Selenium is a widely popular test automation framework as it is compatible with C# and other popular programming languages. It is predominantly used for cross-browser testing as it enables interactions with the web elements (present on a web page) via Selenium WebDriver. It supports all popular web browsers: Firefox, Chrome, Safari, Internet Explorer, Microsoft Edge, etc. We have covered the Selenium framework and Selenium WebDriver architecture in more detail in our earlier blogs. You should definitely check them out in case you are relatively new to the Selenium framework. Test frameworks compatible with Selenium can be used to perform automated browser testing or cross-browser testing of website/web applications. In this Selenium C# tutorial, we have a look at the MSTest framework, which is the default test framework for testing. Net applications. We will also cover the aspects related to cross-browser testing and parallel testing with MSTest. Below are some of the sub-topics that are covered as a part of this MSTest tutorial. MSTest framework for Selenium automated testing is the default test framework that comes along with Visual Studio. In the earlier days, it started as a command-line tool for executing tests. It is also referred to as Visual Studio Unit Testing Framework; however, the name MSTest is more synonymous with the developers. The MSTest framework provides the necessary tools to verify & validate your source code. The framework recognizes tests via the different attributes/annotations under which the test code is present. Some of the popular attributes are [TestInitialize], [TestMethod], [TestCleanup], etc. We will have a detailed look at each of these attributes in further sections of this MSTest tutorial. Since the MSTest framework comes pre-bundled with Visual Studio, developers who use the Visual Studio IDE for development & testing prefer the MSTest framework over other test frameworks like NUnit, xUnit. Net, etc. However, the choice and preference will also depend on the type & complexity of the project. For development, we are making use of the Community Edition of Visual Studio 2019; the same can be downloaded from the official download site of Visual Studio. You also have the option to choose from the Professional or Enterprise edition, though the choice should solely depend upon your project requirements. The necessary packages are selected for the installation since the packages occupy a good amount of disk space after installation. Once the installation is complete, we have to install the required packages for executing the tests based on the MSTest framework. Every test framework requires the corresponding Test Adapter to be installed, as the test adapter is an enabler for executing the test code. As this Selenium C# tutorial is focused on the MSTest framework, you have to install MSTest Adapter to run MSTests. In order to install the required packages, perform the following steps: In case you have not created an MSTest Test Project, you can still install the MSTest framework using the ‘NuGet Package Manager Console commands’ or using the NuGet GUI. At the time of this blog, the latest version of the MSTest framework and MSTest Adapter was 2.2.1, respectively. You can download and install the MSTest framework by either of the two methods, as shown below: a. PM (Package Manager) commands from the ‘‘NuGet Package Manager Console” – For executing commands from the NuGet PM console, go to ‘Tools’ -> ‘NuGet Package Manager’ -> ‘Package Manager Console.’ To install the packages, we make use of the Install-Package command with the required as the argument to the command. The installation screenshots are shown below: You can confirm whether the packages are installed or not by executing the command Get-Package on the Package Manager Console. Shown below is the command execution output: b. NuGet Package Manager – To open the NuGet Package Manager, go to ‘Tools’ -> ‘NuGet Package Manager’ -> ‘Manage NuGet Packages for Solution.’ In the Browse section, search for the following packages and click Install: In this MSTest tutorial, any reference to the MSTest framework refers to MSTest v2, i.e., version 2.2.1. The M2Test V2 framework was introduced a couple of years back with powerful features that are ideal for using the MSTest framework for cross-browser testing. Some of the striking features of MSTest V2 are below: The MSTest V2 portfolio comprises the framework, adapter, templates, etc.

Continue reading...