0
我正在尝试写一些类似于Nunit报告分析器/收集器的失败测试,并且在尝试反序列化测试报告时被卡住。反序列化可能具有不同元素但具有相同类别的XML集合
NUnit的报告具有以下结构:
<test-results ... >
<test-suite>
<results>
<test-suite> or <test-case> bunch of elements
<failure> // optional
</results>
</test-suite>
</test-results>
所以测试套件的元素可能有两种结果的收集与其他测试套件的元素或结果与收集测试案例元素。 由于测试套件已经相同的属性的测试情况下,它可以被序列化为一种类型的类:
[Serializable()]
public class TestResult
{
[XmlAttribute("name")]
public String Name { get; set; }
[XmlAttribute("executed")]
public String Executed { get; set; }
[XmlAttribute("success")]
public String Success { get; set; }
[XmlElement("failure", IsNullable = true)]
public Failure Failure { get; set; }
[XmlElement("results")]
public Results Results { get; set; }
[XmlAttribute("result")]
public String Result { get; set; }
[XmlAttribute("time")]
public String Time { get; set; }
[XmlAttribute("asserts")]
public String Asserts { get; set; }
}
[Serializable()]
public class TestCase : TestResult
{
}
[Serializable()]
public class TestSuite : TestResult
{
[XmlAttribute("type")]
public String Type { get; set; }
}
和结果类假设为具有测试套件或测试箱子的列表:
[Serializable()]
public class Results
{
[XmlArray("results")]
[XmlArrayItem("test-case", Type = typeof(TestCase))]
[XmlArrayItem("test-suite", Type = typeof(TestSuite))]
public List<Result> Result { get; set; }
}
这里TestCase和TestSuite是Result的空子类,因为arrtibutes和元素是相同的。从集合中没有这种方式序列化的项目。如果我试图为每个项目指定多个ArrauItem-s而没有专门的类型,那么pardser认为它是无暧昧的。
我怎样才能实际serialzie收集与不同但相关的元素?