コード例 #1
0
        protected override void HandleNewSpec(BeginNewSpec newSpec)
        {
            base.HandleNewSpec(newSpec);

            _session = new SpecSession();
            _session.OnBegin(newSpec);
        }
コード例 #2
0
        private static void ReportTestMessages(SpecSession session, Dictionary <int, UnitTestResult> nodeResults, UnitTestResult specResult, SpecLog log)
        {
            foreach (var(_, message) in session.Messages)
            {
                var textMessage = $"[{message.When:G}] {message.Message}";

                Output output;
                if (nodeResults.TryGetValue(message.NodeIndex, out var result))
                {
                    if (result.Output == null)
                    {
                        result.Output = new Output();
                    }

                    output = result.Output;
                }
                else
                {
                    if (specResult.Output == null)
                    {
                        specResult.Output = new Output();
                    }

                    output = specResult.Output;
                }

                output.StdOut.Add(textMessage);
                output.DebugTrace.Add(textMessage);
            }

            specResult.Output = specResult.Output ?? new Output();
            specResult.Output.StdErr.AddRange(log.AggregatedTimelineLog);
        }
コード例 #3
0
        protected override void HandleEndSpec(EndSpec endSpec)
        {
            base.HandleEndSpec(endSpec);

            _session.OnEnd(endSpec);
            ReportSpec(_session, _testRun, _computerName, endSpec.Log);

            _session = null;
        }
コード例 #4
0
        private static void ReportSuccess(SpecSession session, Dictionary <int, UnitTestResult> nodeResults)
        {
            foreach (var(time, message) in session.Successes)
            {
                var result = nodeResults[message.NodeIndex];
                result.Outcome = TestOutcome.Passed;
                result.EndTime = time;
                result.Output  = new Output();

                result.Output.StdOut.Add(message.Message);
                result.Output.DebugTrace.Add(message.Message);
            }
        }
コード例 #5
0
        private static void ReportSpec(SpecSession session, TestRun testRun, string computerName, SpecLog log)
        {
            var begin     = session.Begin.Value;
            var beginTime = session.Begin.Time;

            var test       = testRun.AddUnitTest(begin.ClassName, begin.MethodName, $"{begin.ClassName}.{begin.MethodName}");
            var specResult = test.AddResult(begin.MethodName, computerName);

            var nodeResults = new Dictionary <int, UnitTestResult>();

            ReportNodes(begin, specResult, beginTime, nodeResults);
            ReportSuccess(session, nodeResults);
            ReportFailure(session, nodeResults, log);

            specResult.Outcome   = GetCombinedTestOutcome(nodeResults.Values);
            specResult.StartTime = beginTime;
            specResult.EndTime   = session.End.Time;

            ReportTestMessages(session, nodeResults, specResult, log);
        }
コード例 #6
0
        private static void ReportFailure(SpecSession session, Dictionary <int, UnitTestResult> nodeResults, SpecLog log)
        {
            foreach (var(time, message) in session.Fails)
            {
                var result = nodeResults[message.NodeIndex];
                result.Outcome = TestOutcome.Failed;
                result.EndTime = time;

                result.Output = new Output();
                result.Output.StdErr.Add(message.Message);

                var nodeLog = log.NodeLogs.Find(n => n.NodeIndex == message.NodeIndex);
                if (nodeLog.Log != null)
                {
                    result.Output.StdErr.AddRange(nodeLog.Log);
                }

                result.Output.DebugTrace.Add(message.Message);
                result.Output.ErrorInfo = new ErrorInfo()
                {
                    Message = message.Message
                };
            }
        }