Features

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.Remote;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Text;
using TestingBot;

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()
    {
      DesiredCapabilities capability = new DesiredCapabilities();

      String key = Environment.GetEnvironmentVariable("TB_KEY");
      if(key == null)
      {
        key = ConfigurationManager.AppSettings.Get("key");
      }

      String secret = Environment.GetEnvironmentVariable("TB_SECRET");
      if (secret == null)
      {
        secret = ConfigurationManager.AppSettings.Get("secret");
      }

      capability.SetCapability("key", key);
      capability.SetCapability("secret", secret);

      driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub/"), capability);
    }

    [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.


IWebDriver driver;
DesiredCapabilities desiredCap = new DesiredCapabilities();
desiredCap.SetCapability("key", "key");
desiredCap.SetCapability("secret", "secret");

driver = new RemoteWebDriver(
  new Uri("https://hub.testingbot.com/wd/hub/"), desiredCap
);

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



Testing Internal Websites

We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation 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 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/"), capability);

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

[TearDown]
public void CleanUp()
{
    bool passed = true || false;
    try
    {
        // Logs the result to TestingBot
        ((IJavaScriptExecutor)driver).ExecuteScript("tb:test-result=" + (passed ? "passed" : "failed"));
    }
    finally
    {
        // Terminates the remote webdriver session
        driver.Quit();
    }
}

Other C# Framework examples

  • NUnit

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

  • PNunit

    With PNUnit you can run several tests in parallel.

  • SpecFlow

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