public string ToString(TestResult result, bool withTrail) { return string.Format("\"{1}\", \"{2}\", \"{3}\", \"{4}\", \"{5}\", \"{6}\", \"{7}\"{0}", withTrail ? Environment.NewLine : string.Empty, RemoveNewLines(result.FullName), result.State, result.TimeTaken, RemoveNewLines(result.ErrorMessage), RemoveNewLines(result.StackTrace), result.CreateDateTimeString, result.Assembly); }
public string ToString(TestResult result, bool withTrail) { return string.Format("{{\"test\":\"{1}\", \"state\":\"{2}\", \"timetaken\":\"{3}\", \"errormessage\":\"{4}\", \"stacktrace\":\"{5}\", \"createdate\":\"{6}\", \"assembly\":\"{7}\"}}{0}", withTrail ? ("," + Environment.NewLine) : string.Empty, JsonFormat(result.FullName), result.State, result.TimeTaken, JsonFormat(result.ErrorMessage), JsonFormat(result.StackTrace), JsonFormat(result.CreateDateTimeString), JsonFormat(result.Assembly)); }
public string ToString(TestResult result, bool withTrail) { return string.Format("<TestResult>{0}<Test>{2}</Test>{0}<State>{3}</State>{0}<TimeTaken>{4}</TimeTaken>{0}<ErrorMessage>{5}</ErrorMessage>{0}<StackTrace>{6}</StackTrace>{0}<CreateDate>{7}</CreateDate>{0}<Assembly>{8}</Assembly>{0}</TestResult>{1}", Environment.NewLine, withTrail ? Environment.NewLine : string.Empty, result.FullName.ToHtmlString(), result.State, result.TimeTaken, result.ErrorMessage.ToHtmlString(), result.StackTrace.ToHtmlString(), result.CreateDateTimeString.ToHtmlString(), result.Assembly.ToHtmlString()); }
public string ToString(TestResult result, bool withTrail) { return string.Format("<div class='test-result'><span class='test-name'><strong>{0}</strong></span><p class='test-details'><span class='assembly'><strong>Assembly</strong>: {1}</span><br/><span class='state'><strong>State</strong>: {2}</span><br/><span class='time-taken'><strong>Time Taken</strong>: {3}</span><br/><span class='create-date'><strong>Create Date</strong>: {4}</span></p>{5}</div><hr/>", result.FullName.ToHtmlString(), result.Assembly.ToHtmlString(), result.State, result.TimeTaken, result.CreateDateTimeString.ToHtmlString(), result.State == TestResultState.Success ? string.Empty : string.Format("<p class='error-message'><strong>Error Message</strong>:{0}<pre>{1}</pre></p><p class='stack-trace'><strong>StackTrace</strong>:{0}<pre>{2}</pre></p>", Environment.NewLine, result.ErrorMessage.ToHtmlString(), result.StackTrace.ToHtmlString())); }
public string ToString(TestResult result, bool withTrail) { return string.Format("Test: {2}{0}Assembly: {3}{0}State: {4}{0}Time Taken: {5}{0}Create Date: {6}{7}{1}", Environment.NewLine, withTrail ? Environment.NewLine + "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =" + Environment.NewLine : string.Empty, result.FullName, result.Assembly, result.State, result.TimeTaken, result.CreateDateTimeString, result.State == TestResultState.Success ? string.Empty : string.Format("{0}{0}Error Message: {1}{0}{0}StackTrace:{0}{2}", Environment.NewLine, result.ErrorMessage, result.StackTrace)); }
private void EdisonContext_OnTestResult(TestResult result) { CurrentNumberOfTestsRun++; AddFailedTestResult(result); UpdateProgress(); }
private void AddFailedTestResult(TestResult result) { if (result.State == TestResultState.Success) { return; } if (FailedTestListBox.IsDisposed) { return; } if (result.IsFailure) { CurrentNumberOfFailedTests++; } else if (result.IsError) { CurrentNumberOfErroredTests++; } try { if (FailedTestListBox.InvokeRequired) { FailedTestListBox.BeginInvoke((MethodInvoker)delegate { FailedTestListBox.Items.Add(result); }); } else { FailedTestListBox.Items.Add(result); } } catch (ObjectDisposedException) { } }
private void PostResultToUrl(TestResult result) { if (string.IsNullOrWhiteSpace(Context.TestResultURL)) { return; } var output = OutputRepositoryFactory.Get(Context.OutputType); var value = string.Empty; switch (Context.OutputType) { case OutputType.Csv: value = output.OpenTag + Environment.NewLine + output.ToString(result, false); break; default: value = output.ToString(result, false); break; } if (string.IsNullOrWhiteSpace(value)) { return; } var request = WebRequestRepository.Create(Context.TestResultURL + "?TestRunId=" + StringExtension.Safeguard(Context.TestRunId).ToUrlString()); request.Method = "POST"; request.ContentType = output.ContentType; var bytes = Encoding.ASCII.GetBytes(value); request.ContentLength = bytes.Length; using (var stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } using (var response = request.GetResponse()) { Logger.Instance.WriteMessage("Result posted to TestResultURL"); } }
public bool AddOrUpdate(TestResult result) { var response = false; var _result = default(TestResult); var key = result.Assembly + "." + result.FullName; if (Results.TryGetValue(key, out _result)) { if (_result != default(TestResult) && _result.State != TestResultState.Success) { response = Results.TryUpdate(key, result, _result); } } else { response = Results.TryAdd(key, result); } if (Logger.Instance.ConsoleOutputType != OutputType.None) { lock (this) { Logger.Instance.WriteTestResult(result); Logger.Instance.WriteSingleLine(Environment.NewLine, Environment.NewLine); } } try { PostResultToUrl(result); } catch (Exception ex) { Logger.Instance.WriteError(string.Format("Failed posting result to TestResultURL:\n{0}", ex.Message)); } if (OnTestResult != default(TestResultEventHandler)) { OnTestResult.Invoke(result); } return response; }
public void BaseTeardown(TestResult result) { Console.WriteLine("This is the base teardown"); }
public void WriteTestResult(TestResult result) { if (ConsoleOutputType == OutputType.None) { return; } WriteMessage(OutputRepository.ToString(result, false), IsSingleOrNoLined); }
public void WriteResultToFile(string filePath, bool lastResult, TestResult result, IOutputRepository output) { FileRepository.AppendAllText(filePath, output.ToString(result, !lastResult), Encoding.UTF8); }
private void RunTestCase(MethodInfo test, TestCaseAttribute testCase, int testRepeat, IEnumerable<MethodInfo> setup, IEnumerable<MethodInfo> teardown) { var timeTaken = new Stopwatch(); var testResult = default(TestResult); var setupDone = false; var teardownDone = false; var testDone = false; try { testResult = new TestResult( TestResultState.Success, Context.CurrentAssembly, test, TestFixtureCase.Parameters, testCase.Parameters, TestFixtureRepeatIndex, testRepeat, string.Empty, string.Empty, TimeSpan.Zero, string.Empty, default(IEnumerable<string>)); timeTaken.Restart(); if (GlobalSetupException != default(Exception)) { testResult = PopulateTestResultOnException(test, testResult, GlobalSetupException, false, false, setupDone, teardownDone, testDone, timeTaken.Elapsed); } else if (ActivatorException != default(Exception)) { testResult = PopulateTestResultOnException(test, testResult, ActivatorException, true, true, true, true, true, timeTaken.Elapsed); } else if (FixtureSetupException != default(Exception)) { testResult = PopulateTestResultOnException(test, testResult, FixtureSetupException, true, false, setupDone, teardownDone, testDone, timeTaken.Elapsed); } else { //setup ReflectionRepository.Invoke(setup, Activator); setupDone = true; //test ReflectionRepository.Invoke(test, Activator, testCase.Parameters); testDone = true; testResult = PopulateTestResult(test, testResult, TestResultState.Success, timeTaken.Elapsed); //teardown ReflectionRepository.Invoke(teardown, Activator, testResult); teardownDone = true; } timeTaken.Stop(); } catch (Exception ex) { testResult = PopulateTestResultOnException(test, testResult, ex, true, true, setupDone, teardownDone, testDone, timeTaken.Elapsed); //teardown if (testResult.State != TestResultState.TeardownError && testResult.State != TestResultState.TeardownFailure) { try { ReflectionRepository.Invoke(teardown, Activator, testResult); } catch (Exception ex2) { testResult = PopulateTestResultOnException(test, testResult, ex2, true, true, true, false, true, timeTaken.Elapsed); } } if (timeTaken.IsRunning) { timeTaken.Stop(); } } ResultQueue.AddOrUpdate(testResult); }
private TestResult PopulateTestResultOnException(MethodInfo testMethod, TestResult result, Exception ex, bool globalSetup, bool fixSetup, bool setup, bool teardown, bool test, TimeSpan time) { var hasInner = ex.InnerException != default(Exception); var innerExceptionType = hasInner ? ex.InnerException.GetType() : default(Type); var isAssertFail = innerExceptionType == typeof(AssertException); var assertEx = isAssertFail ? (AssertException)ex.InnerException : default(AssertException); var error = isAssertFail ? ex.InnerException.Message : (hasInner ? ex.InnerException.Message : ex.Message); var stack = isAssertFail ? ex.InnerException.StackTrace : (hasInner ? ex.InnerException.StackTrace : ex.StackTrace); var state = TestResultState.Failure; if (!globalSetup) { state = isAssertFail ? (assertEx.TestResultState != TestResultState.Failure ? assertEx.TestResultState : TestResultState.GlobalSetupFailure) : TestResultState.GlobalSetupError; } else if (!fixSetup) { state = isAssertFail ? (assertEx.TestResultState != TestResultState.Failure ? assertEx.TestResultState : TestResultState.TestFixtureSetupFailure) : TestResultState.TestFixtureSetupError; } else if (!setup) { state = isAssertFail ? (assertEx.TestResultState != TestResultState.Failure ? assertEx.TestResultState : TestResultState.SetupFailure) : TestResultState.SetupError; } else if (!test) { if (hasInner && CheckExpectedException(testMethod, isAssertFail, ex.InnerException)) { return PopulateTestResult(testMethod, result, TestResultState.Success, time); } state = isAssertFail ? assertEx.TestResultState : TestResultState.Error; } else if (!teardown) { state = isAssertFail ? (assertEx.TestResultState != TestResultState.Failure ? assertEx.TestResultState : TestResultState.TeardownFailure) : TestResultState.TeardownError; } else { state = TestResultState.Error; } return PopulateTestResult(testMethod, result, state, time, error, stack); }
private TestResult PopulateTestResult(MethodInfo testMethod, TestResult result, TestResultState state, TimeSpan time, string errorMessage = "", string stackTrace = "") { result.State = state; result.ErrorMessage = errorMessage; result.StackTrace = stackTrace; result.TimeTaken = time; if (testMethod != default(MethodInfo)) { result.Authors = ReflectionRepository.GetAuthors(testMethod); result.Version = ReflectionRepository.GetVersion(testMethod); } return result; }
public void Teardown(TestResult result) { Console.WriteLine("This is the teardownz"); test = "err?"; }
public string ToString(TestResult result, bool withTrail) { return string.Empty; }