1
/***********************************************************************
4
* Copyright (C) 2004 Novell, Inc.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public
17
* License along with this program; if not, write to the Free
18
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
***********************************************************************/
27
using System.Collections;
30
/// Parses test result files and creates a summary report.
35
/// The test result files suffix.
37
const string RESULTS_SUFFIX = "*.test.xml";
40
/// The directory containing the test result files.
45
/// The text writer for the summary report.
50
/// The total number of test cases.
55
/// The total number of test cases that ran.
60
/// The total number of test cases that passed.
65
/// The total time required to run the test cases.
70
/// A string list of the number of fails in each test result file.
77
/// <param name="dir">The directory with the test result files.</param>
78
/// <param name="writer">The writer for the summary report.</param>
79
public Report(string dir, TextWriter writer)
83
this.failList = new ArrayList();
87
/// Parse the test result files in the directory.
91
writer.WriteLine("Parsing test result files...");
94
if (Directory.Exists(dir))
96
String[] files = Directory.GetFiles(dir, RESULTS_SUFFIX);
98
foreach(string file in files)
100
writer.WriteLine("Parsing: {0}", Path.GetFileName(file));
108
/// Parse a test result file.
110
/// <param name="file">The test result file.</param>
111
void ParseTestFile(string file)
118
// find a component name
119
string name = Path.GetFileNameWithoutExtension(file);
120
name = Path.GetFileNameWithoutExtension(name);
123
XmlDocument doc = new XmlDocument();
126
foreach (XmlElement node in doc.GetElementsByTagName("test-case"))
130
if (bool.Parse(node.GetAttribute("executed")))
134
if (bool.Parse(node.GetAttribute("success")))
140
// not all test-case elementes have a time
141
string time = node.GetAttribute("time");
142
if ((time != null) && (time.Length > 0))
144
totalTime += Double.Parse(time);
149
if ((fails = runs - passes) > 0)
151
failList.Add(String.Format("{0,4}: {1}", fails, name));
157
totalPasses += passes;
161
/// Write the summary report.
165
const string HEADER = "------------ TEST REPORT ------------";
169
writer.WriteLine(HEADER);
172
writer.WriteLine("TEST CASE RESULTS");
174
writer.WriteLine(" Total: {0}", totalCases);
175
writer.WriteLine(" Ran: {0}", totalRuns);
176
writer.WriteLine(" Passed: {0} [ {1:p1} ]", totalPasses,
177
(totalRuns > 0 ? (double)totalPasses/(double)totalRuns : 0));
179
writer.WriteLine(" Time: {0} seconds", totalTime);
183
writer.WriteLine("FAILED TEST CASES");
186
foreach(string fail in failList)
188
writer.WriteLine(fail);
192
writer.WriteLine(HEADER);
199
/// <param name="args">Command-line arguments.</param>
200
/// <returns>The process result.</returns>
202
static int Main(string[] args)
205
if (args.Length != 1)
207
Console.WriteLine("USAGE: Report.exe [directory]");
212
// create the report object
213
Report report = new Report(args[0], Console.Out);
215
// parse the test result files
218
// write the summary report
219
report.WriteSummary();