---
title: MbUnit C# Automated Selenium Testing Framework
description: MbUnit 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/mbunit
  md: https://testingbot.com/support/web-automate/selenium/csharp/mbunit/index.md
---
# C# Automated Testing with MbUnit

MbUnit (previously named GUnit) is a generative test unit framework, built for C sharp testing. MbUnit implements the Simple Test Pattern and makes it really easy to use fixtures.

## Your first MbUnit test

Please see the example test below, using MbUnit and Gallio framework:

**SingleTest.cs** : 

    using Gallio.Framework;
    using MbUnit.Framework;
    using MbUnit.Framework.ContractVerifiers;
    using OpenQA.Selenium;
    using System.Collections.Generic;
    
    namespace TestingBot
    {
      [TestFixture]
      public class SingleTest : TestingBotMBUnitTest
      {
        public SingleTest() : base("single", "chrome") { }
    
        [Test]
        public void SearchGoogle()
        {
          driver.Navigate().GoToUrl("https://www.google.com/ncr");
          IWebElement query = driver.FindElement(By.Name("q"));
          query.SendKeys("TestingBot");
          query.Submit();
          System.Threading.Thread.Sleep(5000);
          Assert.AreEqual("TestingBot - Google Search", driver.Title);
        }
      }
    }

**TestingBotMBUnitTest.cs** : 

    using Gallio.Framework;
    using MbUnit.Framework;
    using MbUnit.Framework.ContractVerifiers;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using OpenQA.Selenium.Remote;
    using System;
    using System.Collections.Generic;
    
    namespace TestingBot
    {
      [TestFixture]
      public class TestingBotMBUnitTest
      {
        protected IWebDriver driver;
        protected string profile;
        protected string environment;
    
        public TestingBotMBUnitTest(string profile, string environment = "chrome")
        {
          this.profile = profile;
          this.environment = environment;
        }
    
        [FixtureSetUp]
        public void Init()
        {
          string key = Environment.GetEnvironmentVariable("TESTINGBOT_KEY");
          string secret = Environment.GetEnvironmentVariable("TESTINGBOT_SECRET");
    
          ChromeOptions options = new ChromeOptions();
          options.BrowserVersion = "latest";
          options.PlatformName = "WIN11";
    
          var tbOptions = new Dictionary<string, object>
          {
              ["key"] = key,
              ["secret"] = secret,
              ["name"] = profile
          };
          options.AddAdditionalOption("tb:options", tbOptions);
    
          driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub"), options);
        }
    
        [FixtureTearDown]
        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";
    
    var tbOptions = new Dictionary<string, object>
    {
        ["key"] = "API_KEY",
        ["secret"] = "API_SECRET"
    };
    options.AddAdditionalOption("tb:options", tbOptions);
    
    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:

    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.

Please see our [PNUnit documentation](https://testingbot.com/support/web-automate/selenium/csharp/pnunit) for parallel testing.

### 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:

    [FixtureTearDown]
    public void CleanUp()
    {
        bool passed = TestContext.CurrentContext.Outcome.Status == Gallio.Model.TestStatus.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.

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

MbUnit is a generative test unit framework, built for C sharp testing.

### 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)
