Someone here doesn't get Test Driven Development
Trying to get a report of a test run, a shady guy around here has wrote the following code, included in full:
private DataSet ExtractResult(TestSuiteResult result)
{
DataSet res = new DataSet("AllResult");
res.Tables.Add ( "Diagnostics" );
res.Tables["Diagnostics"].Columns.Add(new DataColumn("Description", typeof(string)));
res.Tables["Diagnostics"].Columns.Add(new DataColumn("Passed", typeof(bool)));
res.Tables["Diagnostics"].Columns.Add(new DataColumn("Message", typeof(string)));
foreach (TestSuiteResult o in result.Results)
{
foreach (TestSuiteResult o1 in o.Results)
{
foreach (TestSuiteResult o2 in o1.Results)
{
foreach (TestSuiteResult o3 in o2.Results)
{
foreach (TestSuiteResult o4 in o3.Results)
{
foreach (TestSuiteResult o5 in o4.Results)
{
foreach (TestCaseResult o6 in o5.Results)
{
DataRow row = res.Tables["Diagnostics"].NewRow();
row["Description"] = o6.Name.Substring ( o6.Name.LastIndexOf ( '.')+1);
row["Passed"] = o6.IsSuccess;
row ["Message"] = o6.Message;
res.Tables["Diagnostics"].Rows.Add(row);
}
}
}
}
}
}
}
return res;
}
After thumping him on the head, I replaced the code with this:
XmlResultVisitor visitor = new XmlResultVisitor(sw, result);
result.Accept(visitor);
visitor.Write();
If it take more than 15 lines to do something, think again. And for crying out LOUD, open reflector, have a look. Please!
And on the same note, do read carefully the exception messages that you get, including the stack. "It fails" is utterly meaningless to me.
Comments
Comment preview