/// <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); }
/// <summary> /// runs the given test /// </summary> /// <param name="testinf"></param> /// <param name="errorReason"></param> /// <param name="runCancelled">cancellation delegate, holds the function that checks cancellation</param> /// <returns></returns> public TestRunResults RunTest(TestInfo testinf, ref string errorReason, RunCancelledDelegate runCancelled) { TestRunResults runDesc = new TestRunResults(); ConsoleWriter.ActiveTestRun = runDesc; ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running: " + testinf.TestPath); runDesc.ReportLocation = Helper.CreateTempDir(); runDesc.ErrorDesc = errorReason; runDesc.TestPath = testinf.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); } //write the input parameter xml file for the API test string paramsFile = Path.GetTempFileName(); string paramFileContent = testinf.GenerateAPITestXmlForTest(); string argumentString = ""; if (!string.IsNullOrWhiteSpace(paramFileContent)) { File.WriteAllText(paramsFile, paramFileContent); argumentString = String.Format("{0} \"{1}\" {2} \"{3}\" {4} \"{5}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation, STRunnerInputParamsArg, paramsFile); } else { argumentString = String.Format("{0} \"{1}\" {2} \"{3}\"", STRunnerTestArg, testinf.TestPath, STRunnerReportArg, runDesc.ReportLocation); } Stopwatch s = Stopwatch.StartNew(); runDesc.TestState = TestState.Running; if (!ExecuteProcess(fileName, argumentString, ref errorReason)) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = errorReason; } else { runDesc.ReportLocation = Path.Combine(runDesc.ReportLocation, "Report"); if (!File.Exists(Path.Combine(runDesc.ReportLocation, "Results.xml"))) { runDesc.TestState = TestState.Error; runDesc.ErrorDesc = "No Results.xml file found"; } } runDesc.Runtime = s.Elapsed; return(runDesc); }