Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace NunitReport
{
class ReportParser
{
private static List<XmlNode> cases = new List<XmlNode>();
static void ParseTestSuite(XmlNode node)
{
foreach (XmlNode child in node.ChildNodes)
{
if (child.Name == "test-suite")
{
ParseTestSuite(child);
}
else if (child.Name == "test-case")
{
cases.Add(child);
}
}
}
static void CountGrades()
{
string configPath = @"../../../grades/Grades.json";
JObject grades = JObject.Parse(File.ReadAllText(configPath));
JArray tasks = (JArray) grades["Tasks"];
var countedGrades = new Dictionary<string, int>();
foreach (XmlNode testcase in cases)
{
string caseClass = testcase.Attributes["classname"].Value.Split('.')[0];
string caseName = testcase.Attributes["name"].Value;
foreach (JObject task in tasks)
{
if ((string) task["name"] == caseClass)
{
int maxGrade = (int) task["grades"][caseName];
if (testcase.Attributes["result"].Value == "Passed")
{
if (!countedGrades.ContainsKey(caseClass))
{
countedGrades[caseClass] = 0;
}
countedGrades[caseClass] += maxGrade;
}
}
}
//System.Console.Out.WriteLine(countedGrades[caseClass]);
}
foreach (KeyValuePair<string, int> g in countedGrades)
{
if (g.Value > 0)
{
double grade = g.Value;
grade *= 0.6;
System.Console.Out.WriteLine(g.Key + " = " + grade.ToString());
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
}
}
}
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"../../../TestResult.xml");
// XmlNodeList nodes = doc.DocumentElement.SelectNodes("test-run/test-suite");
XmlNodeList nodes = doc.DocumentElement.ChildNodes;
foreach (XmlNode node in nodes)
{
Console.Out.WriteLine(node.Name);
if (node.Name == "test-suite")
{
ParseTestSuite(node);
}
}
CountGrades();
System.Console.WriteLine("number of running tests: " + cases.Count);
}
}
class ReportNode
{
public string id;
public string title;
public string author;
}
}