1 #region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
2 /************************************************************************************
4 ' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
5 ' Copyright © 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
20 ' or Copyright © 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
33 using System.Globalization;
39 /// Summary description for XmlResultVisitor.
41 public class XmlResultVisitor : ResultVisitor
43 private XmlTextWriter xmlWriter;
45 public XmlResultVisitor(string fileName, TestResult result)
47 ResultSummarizer summaryResults = new ResultSummarizer(result);
50 xmlWriter = new XmlTextWriter (fileName, null);
54 Console.Error.WriteLine(e.StackTrace);
57 xmlWriter.Formatting = Formatting.Indented;
58 xmlWriter.WriteStartDocument(false);
59 xmlWriter.WriteComment("This file represents the results of running a test suite");
61 xmlWriter.WriteStartElement("test-results");
63 xmlWriter.WriteAttributeString("name", summaryResults.Name);
64 xmlWriter.WriteAttributeString("total", summaryResults.ResultCount.ToString());
65 xmlWriter.WriteAttributeString("failures", summaryResults.Failures.ToString());
66 xmlWriter.WriteAttributeString("not-run", summaryResults.TestsNotRun.ToString());
68 DateTime now = DateTime.Now;
69 xmlWriter.WriteAttributeString("date", now.ToShortDateString());
70 xmlWriter.WriteAttributeString("time", now.ToShortTimeString());
74 public void visit(TestCaseResult caseResult)
76 xmlWriter.WriteStartElement("test-case");
77 xmlWriter.WriteAttributeString("name",caseResult.Name);
78 xmlWriter.WriteAttributeString("executed", caseResult.Executed.ToString());
79 if(caseResult.Executed)
81 xmlWriter.WriteAttributeString("success", caseResult.IsSuccess.ToString());
83 xmlWriter.WriteAttributeString("time", caseResult.Time.ToString("#####0.000", NumberFormatInfo.InvariantInfo));
85 if(caseResult.IsFailure)
87 if(caseResult.IsFailure)
88 xmlWriter.WriteStartElement("failure");
90 xmlWriter.WriteStartElement("error");
92 xmlWriter.WriteStartElement("message");
93 xmlWriter.WriteCData(caseResult.Message);
94 xmlWriter.WriteEndElement();
96 xmlWriter.WriteStartElement("stack-trace");
97 if(caseResult.StackTrace != null)
98 xmlWriter.WriteCData(StackTraceFilter.Filter(caseResult.StackTrace));
99 xmlWriter.WriteEndElement();
101 xmlWriter.WriteEndElement();
107 xmlWriter.WriteStartElement("reason");
108 xmlWriter.WriteStartElement("message");
109 xmlWriter.WriteCData(caseResult.Message);
110 xmlWriter.WriteEndElement();
111 xmlWriter.WriteEndElement();
114 xmlWriter.WriteEndElement();
117 public void visit(TestSuiteResult suiteResult)
119 xmlWriter.WriteStartElement("test-suite");
120 xmlWriter.WriteAttributeString("name",suiteResult.Name);
121 xmlWriter.WriteAttributeString("success", suiteResult.IsSuccess.ToString());
122 xmlWriter.WriteAttributeString("time", suiteResult.Time.ToString());
124 xmlWriter.WriteStartElement("results");
125 foreach (TestResult result in suiteResult.Results)
129 xmlWriter.WriteEndElement();
131 xmlWriter.WriteEndElement();
136 xmlWriter.WriteEndElement();
138 xmlWriter.WriteEndDocument();