Unit Testing Helper

The Remote Test Runner project includes a unit test assistance DLL that enhances its ability to create a detailed report. The detailed report can include the input columns and output columns for each row of a Data-Driven test.

Using the Unit Testing DLL
  1. Reference the UnitTesting.DLL in your Unit Test project.
  2. Within your Test Class several updates need to be made to your existing code. Example code is shown below.
    1. Creating a static private field for an instance of MultiAssertTestClassHelper.
    2. Within the ClassInitialize marked method create the instance of MultiAssertTestClassHelper.
    3. Dispose the instance in the ClassCleanup marked method.
    4. In each of your TestMethod marked functions wrap your existing code in a using statement call to MultiAssertTestClassHelper.GetFunctionHelper.
    5. Inside the using add your inputs.
    6. Replace your Assert.AreEqual calls with the new AreEqual call.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using FCSAmerica.RTR.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RTRSample
    public class DataDrivenSample
        public TestContext TestContext { get; set; }

        private static MultiAssertTestClassHelper _testClassHelper;

        #region Additional test attributes
        public static void MyClassInitialize(TestContext testContext)
            // The name of the class specified in the first parameter is unique for this class.  
            // The value is used in the detail report in RTR.
            _testClassHelper = new MultiAssertTestClassHelper("DataDrivenSample", testContext.TestDir);

        public static void MyClassCleanup()
        public void DataDrivenSampleTestMethod()
            // Setup function helper
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))

                int input1;             

                // Setup inputs
                // The first parameter is the name of the column to appear in the RTR detailed report.
                // The second parameter is the actual data in the column.
                    .AddInput("InputColumn", ref input1)
                    .AddInput("InputColumn2", TestContext.DataRow["InputColumn2"]);
                // Normal call to the code being tested.
                // In this case we are just performing some arithmetic operations.
                int actualSum;
                int actualDifference;
                double actualDivision;

                actualSum = input1 + Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                actualDifference = input1 - Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                actualDivision = input1 / Convert.ToDouble(TestContext.DataRow["InputColumn2"]);
                // Assert the results
                // The first three parameters are the same as those sent to the normal Assert.AreEqual.  
                // The 4th and additional parameter is the name of the assert that will be shown in the RTR detail report.
                //   These assert names must be unique across this function.  Using a fluent call method is not required.
                    .AreEqual<double>(TestContext.DataRow["OutputColumn1"], actualSum, "Sum test", "OutputColumn1")
                    .AreEqual<double>(TestContext.DataRow["OutputColumn2"], actualDifference, "Difference test", "OutputColumn2")
                    .AreEqual<double>(actualDivision, "Division test", "OutputColumn3");

Last edited Mar 27, 2009 at 7:57 PM by jeremy805, version 4


No comments yet.