Ejemplo n.º 1
0
    private void HandleTestFailed(MessageHandlerArgs <ITestFailed> args)
    {
        if (args == null || args.Message == null)
        {
            return;
        }

        FailedTests++;
        string assemblyInfo = GetAssemblyInfo(args.Message.TestAssembly);
        var    sb           = new StringBuilder($"\t[FAIL] {args.Message.TestCase.DisplayName}");

        LogTestDetails(args.Message.Test, OnError, sb);
        sb.AppendLine();
        if (!string.IsNullOrEmpty(assemblyInfo))
        {
            sb.AppendLine($"   Assembly: {assemblyInfo}");
        }

        LogSourceInformation(args.Message.TestCase.SourceInformation, OnError, sb);
        LogFailureInformation(args.Message, OnError, sb);
        sb.AppendLine();
        LogTestOutput(args.Message, OnError, sb);
        sb.AppendLine();
        if (args.Message.TestCase.Traits != null && args.Message.TestCase.Traits.Count > 0)
        {
            foreach (var kvp in args.Message.TestCase.Traits)
            {
                string message = $"   Test trait name: {kvp.Key}";
                OnError(message);
                sb.AppendLine(message);

                foreach (string v in kvp.Value)
                {
                    message = $"      value: {v}";
                    OnError(message);
                    sb.AppendLine(message);
                }
            }
            sb.AppendLine();
        }
        ReportTestCases("   Associated", args.Message.TestCases, args.Message.TestCase, OnDiagnostic);

        FailureInfos.Add(new TestFailureInfo
        {
            TestName = args.Message.Test?.DisplayName,
            Message  = sb.ToString()
        });
        OnInfo($"\t[FAIL] {args.Message.Test.TestCase.DisplayName}");
        OnInfo(sb.ToString());
        OnTestCompleted((
                            TestName: args.Message.Test.DisplayName,
                            TestResult: TestResult.Failed
                            ));
    }
Ejemplo n.º 2
0
        public void TestFinished(ITestResult result)
        {
            if (result.Test is TestSuite)
            {
                //if (!result.IsError && !result.IsFailure && !result.IsSuccess && !result.Executed)
                //Writer.WriteLine ("\t[INFO] {0}", result.Message);
                if (result.ResultState.Status != TestStatus.Failed &&
                    result.ResultState.Status != TestStatus.Skipped &&
                    result.ResultState.Status != TestStatus.Passed &&
                    result.ResultState.Status != TestStatus.Inconclusive)
                {
                    Logger.OnInfo($"\t[INFO] {result.Message}");
                }

                string name = result.Test.Name;
                if (!String.IsNullOrEmpty(name))
                {
                    Logger.OnInfo($"{name} : {result.Duration.TotalMilliseconds} ms\n");
                }

                if (GCAfterEachFixture)
                {
                    GC.Collect();
                }
            }
            else
            {
                var sb = new StringBuilder();
                switch (result.ResultState.Status)
                {
                case TestStatus.Passed:
                    sb.Append("\t[PASS] ");
                    PassedTests++;
                    break;

                case TestStatus.Skipped:
                    sb.Append("\t[IGNORED] ");
                    SkippedTests++;
                    break;

                case TestStatus.Failed:
                    sb.Append("\t[FAIL] ");
                    FailedTests++;
                    break;

                case TestStatus.Inconclusive:
                    sb.Append("\t[INCONCLUSIVE] ");
                    InconclusiveTests++;
                    break;

                default:
                    sb.Append("\t[INFO] ");
                    break;
                }
                TotalTests++;
                sb.Append(result.Test.FixtureType.Name);
                sb.Append(".");
                sb.Append(result.Test.Name);
                string message = result.Message;
                if (!string.IsNullOrEmpty(message))
                {
                    message = message.Replace("\r\n", "\\r\\n");
                    sb.Append($" : {message}");
                }
                Logger.OnInfo(sb.ToString());
                string stacktrace = result.StackTrace;
                if (!string.IsNullOrEmpty(result.StackTrace))
                {
                    string[] lines = stacktrace.Split(new char [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string line in lines)
                    {
                        Logger.OnInfo($"\t\t{line}");
                    }
                }

                if (result.ResultState.Status == TestStatus.Failed)
                {
                    FailureInfos.Add(new TestFailureInfo {
                        TestName = result.Test.FullName,
                        Message  = sb.ToString()
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public void TestFinished(ITestResult result)
        {
            if (result.Test is TestSuite)
            {
                //if (!result.IsError && !result.IsFailure && !result.IsSuccess && !result.Executed)
                //Writer.WriteLine ("\t[INFO] {0}", result.Message);
                if (result.ResultState.Status != TestStatus.Failed &&
                    result.ResultState.Status != TestStatus.Skipped &&
                    result.ResultState.Status != TestStatus.Passed &&
                    result.ResultState.Status != TestStatus.Inconclusive)
                {
                    Logger.OnInfo($"\t[INFO] {result.Message}");
                }

                // the NUnit API here is quite dirty, turs out that if we had an issue with the
                // TestFixrtureSetup, the TestFinished method is never called, but we need to be
                // able to report the errors, so what we can do is, in case of a failed suit, loop
                // over the children and check if the fixture setup was the issue.
                if (result.ResultState.Status == TestStatus.Failed)
                {
                    foreach (var t in result.Children)
                    {
                        if (t.Message != null && t.Message.Contains("TestFixtureSetUp Failed"))
                        {
                            var sb = new StringBuilder();
                            sb.Append("\t[FAIL] ");
                            FailedTests++;
                            sb.Append(t.Test.FixtureType.Name);
                            sb.Append(".");
                            sb.Append(t.Test.Name);
                            string message = result.Message;
                            if (!string.IsNullOrEmpty(message))
                            {
                                message = message.Replace("\r\n", "\\r\\n");
                                sb.Append($" : {message}");
                            }
                            Logger.OnInfo(sb.ToString());
                            // add the failures to be reported at the end of the file
                            FailureInfos.Add(new TestFailureInfo
                            {
                                TestName = t.Test.FullName,
                                Message  = sb.ToString()
                            });
                        } // TestFixtureSetup Failed
                    }
                }

                string name = result.Test.Name;
                if (!String.IsNullOrEmpty(name))
                {
                    Logger.OnInfo($"{name} : {result.Duration.TotalMilliseconds} ms\n");
                }

                if (GCAfterEachFixture)
                {
                    GC.Collect();
                }
            }
            else
            {
                var sb = new StringBuilder();
                switch (result.ResultState.Status)
                {
                case TestStatus.Passed:
                    sb.Append("\t[PASS] ");
                    PassedTests++;
                    ExecutedTests++;
                    break;

                case TestStatus.Skipped:
                    sb.Append("\t[IGNORED] ");
                    SkippedTests++;
                    break;

                case TestStatus.Failed:
                    sb.Append("\t[FAIL] ");
                    FailedTests++;
                    ExecutedTests++;
                    break;

                case TestStatus.Inconclusive:
                    sb.Append("\t[INCONCLUSIVE] ");
                    InconclusiveTests++;
                    ExecutedTests++;
                    break;

                default:
                    sb.Append("\t[INFO] ");
                    break;
                }
                sb.Append(result.Test.FixtureType.Name);
                sb.Append(".");
                sb.Append(result.Test.Name);
                string message = result.Message;
                if (!string.IsNullOrEmpty(message))
                {
                    message = message.Replace("\r\n", "\\r\\n");
                    sb.Append($" : {message}");
                }
                Logger.OnInfo(sb.ToString());
                string stacktrace = result.StackTrace;
                if (!string.IsNullOrEmpty(result.StackTrace))
                {
                    string[] lines = stacktrace.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string line in lines)
                    {
                        Logger.OnInfo($"\t\t{line}");
                    }
                }

                if (result.ResultState.Status == TestStatus.Failed)
                {
                    FailureInfos.Add(new TestFailureInfo
                    {
                        TestName = result.Test.FullName,
                        Message  = sb.ToString()
                    });
                }
            }
        }
Ejemplo n.º 4
0
        public void TestFinished(ITestResult result)
        {
            if (result.Test is TestSuite)
            {
                //if (!result.IsError && !result.IsFailure && !result.IsSuccess && !result.Executed)
                //Writer.WriteLine ("\t[INFO] {0}", result.Message);
                if (result.ResultState.Status != TestStatus.Failed &&
                    result.ResultState.Status != TestStatus.Skipped &&
                    result.ResultState.Status != TestStatus.Passed &&
                    result.ResultState.Status != TestStatus.Inconclusive)
                {
                    Logger.OnInfo("\t[INFO] {0}", result.Message);
                }

                Logger.OnInfo(LogTag, $"{result.Test.FullName} : {result.Duration.TotalMilliseconds} ms");
                if (GCAfterEachFixture)
                {
                    GC.Collect();
                }
            }
            else
            {
                Action <string, string> log           = Logger.OnInfo;
                StringBuilder           failedMessage = null;

                ExecutedTests++;
                if (result.ResultState.Status == TestStatus.Passed)
                {
                    Logger.OnInfo(LogTag, $"\t{result.ResultState.ToString ()}");
                    PassedTests++;
                }
                else if (result.ResultState.Status == TestStatus.Failed)
                {
                    Logger.OnError(LogTag, "\t[FAIL]");
                    log           = Logger.OnError;
                    failedMessage = new StringBuilder();
                    failedMessage.Append(result.Test.FullName);
                    if (result.Test.FixtureType != null)
                    {
                        failedMessage.Append($" ({result.Test.FixtureType.Assembly.GetName ().Name})");
                    }
                    failedMessage.AppendLine();
                    FailedTests++;
                }
                else
                {
                    string status;
                    switch (result.ResultState.Status)
                    {
                    case TestStatus.Skipped:
                        SkippedTests++;
                        status = "SKIPPED";
                        break;

                    case TestStatus.Inconclusive:
                        InconclusiveTests++;
                        status = "INCONCLUSIVE";
                        break;

                    default:
                        status = "UNKNOWN";
                        break;
                    }
                    Logger.OnInfo(LogTag, $"\t[{status}]");
                }

                string message = result.Message?.Replace("\r\n", "\\r\\n");
                if (!String.IsNullOrEmpty(message))
                {
                    log(LogTag, $" : {message}");
                    if (failedMessage != null)
                    {
                        failedMessage.AppendLine(message);
                    }
                }

                string stacktrace = result.StackTrace;
                if (!String.IsNullOrEmpty(result.StackTrace))
                {
                    log(LogTag, result.StackTrace);
                    if (failedMessage != null)
                    {
                        failedMessage.AppendLine();
                        failedMessage.AppendLine(result.StackTrace);
                    }
                }

                if (failedMessage != null)
                {
                    FailureInfos.Add(new TestFailureInfo {
                        TestName = result.Test.FullName,
                        Message  = failedMessage.ToString()
                    });
                }
            }
        }