/// <summary>
/// runs the given test
/// </summary>
/// <param name="testPath"></param>
/// <param name="errorReason"></param>
/// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param>
/// <returns></returns>
public TestRunResults RunTest(string testPath, ref string errorReason, RunCancelledDelegate runCancelled)
{
TestRunResults runDesc = new TestRunResults();
ConsoleWriter.ActiveTestRun = runDesc;
ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testPath);
runDesc.ReportLocation = Helper.CreateTempDir();
runDesc.ErrorDesc = errorReason;
runDesc.TestPath = testPath;
runDesc.TestState = TestState.Unknown;
if (!Helper.IsServiceTestInstalled())
{
runDesc.TestState = TestState.Error;
runDesc.ErrorDesc = string.Format(Resources.LauncherStNotInstalled, System.Environment.MachineName);
ConsoleWriter.WriteErrLine(runDesc.ErrorDesc);
Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed;
return(runDesc);
}
_runCancelled = runCancelled;
if (!_stCanRun)
{
runDesc.TestState = TestState.Error;
runDesc.ErrorDesc = Resources.STExecuterNotFound;
return(runDesc);
}
string fileName = Path.Combine(_stExecuterPath, STRunnerName);
if (!File.Exists(fileName))
{
runDesc.TestState = TestState.Error;
runDesc.ErrorDesc = Resources.STExecuterNotFound;
ConsoleWriter.WriteErrLine(Resources.STExecuterNotFound);
return(runDesc);
}
Stopwatch s = Stopwatch.StartNew();
runDesc.TestState = TestState.Running;
if (!ExecuteProcess(fileName,
String.Format("{0} \"{1}\" {2} \"{3}\" ", STRunnerTestArg, testPath, STRunnerReportArg, runDesc.ReportLocation),
ref errorReason))
{
runDesc.TestState = TestState.Error;
runDesc.ErrorDesc = errorReason;
runDesc.Runtime = s.Elapsed;
return(runDesc);
}
else
{
runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report");
}
runDesc.Runtime = s.Elapsed;
return(runDesc);
}