Developing an output driver

Parent Previous Next

A custom driver is a class implementing the ITestsOutput interface. It must be developed in the domain of a client, without any need to recompile CRA.Core.Preconditions.dll and using the same calls. As an example, lets look at the code of the TestsOutputDefault class:

 

Parameters 

#region Parameters

private static string localLogFileName = "PrePostConditionsLog.txt";
/// <summary>
/// Name of the txt file to output pre and post conditions test results.
/// The default name is PrePostConditionsLog.txt, saved on the same directory where
/// the CRA.Core.Preconditions component is saved; a path can be specified.
/// </summary>
public static string LogFileName
{
get { return localLogFileName; }
set { localLogFileName = value; }
}

#endregion

 

Here the output destination is defined as a file name.  Other parameters might be added.

 

ITestOutput members

#region ITestsOutput Members

/// <summary>
/// This methods allows saving on file the tests results.
/// </summary>
/// <param name="result">a string containing all tests results</param>
/// <param name="saveLog">false=on screen, true=on file</param>
/// <param name="componentName">the name of the component</param>
public void TestsOut(string result, bool saveLog, string componentName)
{
if (saveLog == false)
{
//display on screen
System.Windows.Forms.MessageBox.Show(result, componentName + " - Violation of pre/post-conditions");
}
else
{
//save on file localLogFileName
DateTime dt = DateTime.Now;
FileStream file = new FileStream(localLogFileName,
FileMode.Append,
FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.WriteLine(componentName + " - " + dt + "\r\n" + result);
sw.Close();
file.Close();
}
}

#endregion

 

 






























































Created with the Personal Edition of HelpNDoc: Create HTML Help, DOC, PDF and print manuals from 1 single source