---
title: MSTest Framework C# Automated Selenium Testing Framework
description: MSTest Framework C# automated testing with Selenium and Appium. Run your
  tests on 6100+ real browsers and mobile devices in the TestingBot cloud.
source_url:
  html: https://testingbot.com/support/web-automate/selenium/csharp/mstest
  md: https://testingbot.com/support/web-automate/selenium/csharp/mstest/index.md
---
# C# Automated Testing with MSTest

MSTest framework is a test framework which is included, by default, with Microsoft Visual Studio.   
 It is also referred to as Visual Studio Unit Testing Framework and is popular with developers using the Visual Studio IDE.

MSTest V2 is open-sourced and available on [GitHub](https://github.com/Microsoft/testfx).   
 With MSTest V2 you can easily run tests in parallel, using In-Assembly Parallel (via `Annotations` or `RunSettings`).

## Installation

To get started with MSTest, you'll need to make sure that `MSTest Framework` and `MSTest Adapter` are installed.

You can install the packages via the commandline or with NuGet:

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

## Your first MSTest test

Please see the example test below, using MSTest.   
 The test will start 3 browsers, visit our homepage and print the title.

**SingleTest.cs** : 

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.Collections.Generic;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium.Edge;
    using OpenQA.Selenium.Remote;
    
    [assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)]
    
    namespace MS_Test_Cross_Browser
    {
        [TestClass]
        public class SingleTest
        {
            IWebDriver driver;
    
            [DataTestMethod]
            [DataRow("chrome", "latest", "WIN11")]
            [DataRow("MicrosoftEdge", "latest-1", "WIN11")]
            [DataRow("firefox", "latest", "SONOMA")]
            public void Cross_Browser_Test(String browser, String version, String os)
            {
                DriverOptions options;
    
                switch (browser.ToLower())
                {
                    case "firefox":
                        options = new FirefoxOptions();
                        break;
                    case "microsoftedge":
                        options = new EdgeOptions();
                        break;
                    default:
                        options = new ChromeOptions();
                        break;
                }
    
                options.BrowserVersion = version;
                options.PlatformName = os;
                options.AddAdditionalOption("tb:options", new Dictionary<string, object>
                {
                    ["key"] = "API_KEY",
                    ["secret"] = "API_SECRET",
                    ["name"] = "MSTest with TestingBot"
                });
    
                driver = new RemoteWebDriver(
                    new Uri("https://hub.testingbot.com/wd/hub"),
                    options
                );
    
                driver.Navigate().GoToUrl("https://testingbot.com");
                Console.WriteLine(driver.Title);
            }
    
            [TestCleanup]
            public void Cleanup()
            {
                driver?.Quit();
            }
        }
    }

## Specify Browsers & Devices

To let TestingBot know on which browser/platform/device you want to run your test on, you need to specify the browsername, version, OS and other optional options in the capabilities field.

    ChromeOptions options = new ChromeOptions();
    options.BrowserVersion = "latest";
    options.PlatformName = "WIN11";
    options.AddAdditionalOption("tb:options", new Dictionary<string, object>
    {
        ["key"] = "API_KEY",
        ["secret"] = "API_SECRET",
        ["name"] = "My Test"
    });
    
    IWebDriver driver = new RemoteWebDriver(
        new Uri("https://hub.testingbot.com/wd/hub"),
        options
    );

To see how to do this, please select a combination of browser, version and platform in the drop-down menus below.

  ![OS selected](https://testingbot.com/assets/environments/svg/windows11-0e1b28bc0fdd5034d3e4d3dc8d346c500a8c6522facf4b45d0da56537c1f1c6d.svg) Windows 11 › ![Browser Selected](https://testingbot.com/assets/environments/svg/chrome-c4081ff447d2d898d4afcb8f074a907c960e6f007716c1a1d119eee6803c4042.svg) Chrome 139 

Loading environments...

Please wait while we load the available browsers and platforms.

    

## Testing Internal Websites

We've built [TestingBot Tunnel](https://testingbot.com/support/tunnel), to provide you with a secure way to run tests against your staged/internal webapps.   
 Please see our [TestingBot Tunnel documentation](https://testingbot.com/support/tunnel) for more information about this easy to use tunneling solution.

The example below shows how to easily run a C# test with our Tunnel:

1. [Download our tunnel](https://testingbot.com/support/tunnel) and start the tunnel:

    java -jar testingbot-tunnel.jar key secret

2. Adjust your test: instead of pointing to `'hub.testingbot.com/wd/hub'` like the example above - change it to point to your tunnel's IP address.   
 Assuming you run the tunnel on the same machine you run your tests, change to `'localhost:4445/wd/hub'`. localhost is the machine running the tunnel, 4445 is the default port of the tunnel.

This way your test will go securely through the tunnel to TestingBot and back:

    IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4445/wd/hub"), options);

## Run tests in Parallel

Parallel Testing means running the same test, or multiple tests, simultaneously. This greatly reduces your total testing time.

You can run the same tests on all different browser configurations or run different tests all on the same browser configuration.   
 TestingBot has a large grid of machines and browsers, which means you can use our service to do efficient parallel testing. It is one of the key features we provide to greatly cut down on your total testing time.

To modify the number of parallel tests with MSTest, please use the `Parallelize annotation`:

    [assembly: Parallelize(Workers = 5, Scope = ExecutionScope.MethodLevel)]

This will run the test on 5 workers (= 5 parallel sessions).

### Queuing

Every plan we provide comes with a limit of parallel tests.   
 If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.

## Mark tests as passed/failed

To see if a test passed or not in our member area, or to send additional meta-data to TestingBot, you can use our API.

Please see the example below on how to notify TestingBot about the test success state:

    [TestCleanup]
    public void CleanUp()
    {
        bool passed = TestContext.CurrentTestOutcome == UnitTestOutcome.Passed;
        var sessionId = ((RemoteWebDriver)driver).SessionId.ToString();
        try
        {
            // Report the result to TestingBot via the REST API
            using var client = new System.Net.Http.HttpClient();
            var key = Environment.GetEnvironmentVariable("TESTINGBOT_KEY");
            var secret = Environment.GetEnvironmentVariable("TESTINGBOT_SECRET");
            var auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{key}:{secret}"));
            client.DefaultRequestHeaders.Authorization =
                new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", auth);
            var content = new System.Net.Http.FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("test[success]", passed ? "1" : "0")
            });
            client.PutAsync($"https://api.testingbot.com/v1/tests/{sessionId}", content).Wait();
        }
        finally
        {
            driver.Quit();
        }
    }

## Other C# Framework examples

- [NUnit](https://testingbot.com/support/web-automate/selenium/csharp/nunit)

An unit testing framework that is open source written in C#.

- [PNunit](https://testingbot.com/support/web-automate/selenium/csharp/pnunit)

With PNUnit you can run several tests in parallel.

- [SpecFlow](https://testingbot.com/support/web-automate/selenium/csharp/specflow)

SpecFlow allows you to run Automated .NET tests using Cucumber-compatible Gherkin syntax.

- [MSTest](https://testingbot.com/support/web-automate/selenium/csharp/mstest)

MSTest framework is a test framework which is included, by default, with Microsoft Visual Studio.

- [xUnit](https://testingbot.com/support/web-automate/selenium/csharp/xunit)

xUnit.net is a modern, extensible testing framework for .NET, widely used in the .NET ecosystem.

- [Reqnroll](https://testingbot.com/support/web-automate/selenium/csharp/reqnroll)

Reqnroll is the successor to SpecFlow for BDD testing with Gherkin syntax.

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new)[Slack Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
