示例#1
0
        private void Push(string elementName)
        {
            Debug.WriteLine(elementName, "Start");
            Debug.IndentLevel++;
            Writer w = new Writer();

            w.TextWriter           = new StringWriter();
            w.XmlWriter            = new XmlTextWriter(w.TextWriter);
            w.XmlWriter.Formatting = Formatting.Indented;
            w.Content = new StringBuilder();
            w.Timer   = new Stopwatch();
            if (_writerStack.Count == 0)
            {
                // Write document start as raw to account for dodgy MS code.
                w.XmlWriter.WriteRaw("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>");
                w.XmlWriter.WriteComment("This file represents the results of running a test suite");
                _writerStack.Push(w);
                CurrentWriter.WriteStartElement("test-results");
                // TODO CurrentWriter.WriteAttributeString( "name", testSuite.Assembly.Location );
                CurrentWriter.WriteAttributeString("date", DateTime.Now.ToString("yyyy-MM-dd"));
                CurrentWriter.WriteAttributeString("time", DateTime.Now.ToString("HH:mm:ss"));
                Push(elementName);
            }
            else
            {
                _writerStack.Push(w);
                CurrentWriter.WriteStartElement(elementName);
            }
        }
示例#2
0
        /// <summary>
        /// Notifies the listener at the end of a test.
        /// </summary>s
        public void EndTest(ITest test)
        {
            CurrentWriter.WriteStartElement("test-case");
            CurrentWriter.WriteAttributeString("name", test.Name);
            CurrentWriter.WriteAttributeString("description", test.Description);
            if (test.Result.Status != (TestStatus.Untested | TestStatus.Ignore))
            {
                CurrentWriter.WriteAttributeString("executed", "True");
                CurrentWriter.WriteAttributeString("success", (test.Result.Status == TestStatus.Pass).ToString());
                CurrentWriter.WriteAttributeString("time", new TimeSpan(test.Result.TimeSpan).TotalSeconds.ToString("0.000"));
            }
            else
            {
                CurrentWriter.WriteAttributeString("executed", "False");
            }
            if (test.Result.Status == TestStatus.Ignore)
            {
                CurrentWriter.WriteStartElement("reason");
                CurrentWriter.WriteStartElement("message");
                CurrentWriter.WriteCData(test.Result.Message.ToString());
                CurrentWriter.WriteEndElement();
                CurrentWriter.WriteEndElement();
            }
            else if (test.Result.Status == TestStatus.Fail)
            {
                CurrentWriter.WriteStartElement("failure");
                CurrentWriter.WriteStartElement("message");
                StringBuilder message = new StringBuilder();
                message.Append(test.Result.Message);
                if (test.Result.Output.Length > 0)
                {
                    message.AppendLine("OUTPUT:");
                    message.Append(test.Result.Output);
                }
                CurrentWriter.WriteCData(message.ToString());
                CurrentWriter.WriteEndElement();
                if (test.Result.StackTrace != null)
                {
                    CurrentWriter.WriteStartElement("stack-trace");
                    CurrentWriter.WriteCData(test.Result.StackTrace);
                    CurrentWriter.WriteEndElement();
                }
                CurrentWriter.WriteEndElement();
            }
            CurrentWriter.WriteEndElement();
            switch (test.Result.Status)
            {
            case TestStatus.Untested:
            case TestStatus.Ignore:
                _skipCount += test.TestCount;
                break;

            case TestStatus.Pass:
                _passCount += test.TestCount;
                break;

            case TestStatus.Fail:
                _failCount    += test.TestCount;
                _fixturePassed = false;
                break;

            default:
                break;
            }
        }