Sample 1: Basic Usage

The following sample shows how to create a class for running unit tests with Typemock Isolator. The UnitTestRunner property is used to set the framework that will run the test. The UnitTestRunnerParams property is used to set the runner command line arguments. In this case, only the assembly with the tests is set.

C#

class TestsRunner
{
  private string unitTestRunner;
  private string unitTestRunnerParams;

  /// <summary>
  /// get or sets the unit test runner (nunit, mbunit etc ...)
  /// </summary>
  public string UnitTestRunner  
  {
    get { return unitTestRunner; }
    set { unitTestRunner = value; }
  }

  /// <summary>
  /// get or set the unit test runner parameters
  /// </summary>
  public string UnitTestRunnerParams  
  {
    get { return unitTestRunnerParams; }
    set { unitTestRunnerParams = value; }
  }

  public void RunTest()  
  {           
    //set the process to run and its command line arguments
    ProcessStartInfo info = new ProcessStartInfo(UnitTestRunner, UnitTestRunnerParams );

    //create process with TypeMock enabled
    TypeMockProcess typeMockProcess = new TypeMockProcess(info);

    //run the process
    typeMockProcess.Start();                                       
  }
}

class Program
{
  static void Main(string[] args)
  {
    //calling the code
    TestsRunner runner = new TestsRunner();
    runner.UnitTestRunner = @"C:\Program Files\NUnit-Net-2.0 2.2.8\bin\nunit-console.exe";
    runner.UnitTestRunnerParams = @"..\..\..\..\csharp\bin\Debug\Examples.csharp.dll";
    runner.RunTest();
  }
}