Ejemplo n.º 1
0
        public void OnTestFinished(TestFinishedInfo info)
        {
            var item = new ReportItem
            {
                ThreadName   = _threadName,
                Duration     = (double)info.ExecutionTime,
                TestCase     = info.MethodName,
                TestSuite    = info.TypeName,
                ErrorMessage = "",
                ErrorTrace   = "",
                Status       = "PASSED"
            };

            _reportWriter.AddItemToReport(item);
        }
        public void OnTestEvent(string report)
        {
            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(report);
                var node = xmlDoc.FirstChild;
                if (node.Name != "test-case")
                {
                    return;
                }

                var start = DateTime.Parse(node.Attributes["start-time"].Value);
                var item  = new ReportItem
                {
                    ThreadName = _threadName,
                    StartTime  = (start.ToUniversalTime().Ticks - EpochTicks) / NanosecondsInSecond,
                    Duration   = Double.Parse(node.Attributes["duration"].Value,
                                              NumberStyles.AllowDecimalPoint,
                                              NumberFormatInfo.InvariantInfo),
                    TestCase     = node.Attributes["methodname"].Value,
                    TestSuite    = node.Attributes["classname"].Value,
                    ErrorMessage = "",
                    ErrorTrace   = "",
                    Extras       = GetXmlNodeProperties(node)
                };

                switch (node.Attributes["result"].Value)
                {
                case "Passed":
                    item.Status = "PASSED";
                    break;

                case "Failed":
                    item.Status = "FAILED";
                    var failureNode = node.SelectSingleNode("failure");
                    if (failureNode != null)
                    {
                        item.ErrorMessage = failureNode.SelectSingleNode("message").InnerText.Trim();
                        item.ErrorTrace   = failureNode.SelectSingleNode("stack-trace").InnerText.Trim();
                    }

                    break;

                case "Skipped":
                    item.Status = "SKIPPED";
                    var reasonNode = node.SelectSingleNode("reason");
                    if (reasonNode != null)
                    {
                        item.ErrorMessage = reasonNode.SelectSingleNode("message").InnerText.Trim();
                    }

                    break;
                }

                _reportWriter.AddItemToReport(item);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: {0}", e);
            }
        }