我有一个变量失败,它可以有三个值:通过、失败或错误。我希望在序列化期间发生的是基于值创建一个元素。对于通过,我想忽略该元素。对于失败,我想要一个失败元素。对于错误,我想要一个错误元素。如何才能做到这一点?
在 Test 类中,有一个名为 m_steps 的步骤列表。在 Step 中有一个名为 m_failure 的变量,它保存通过、失败或错误。我希望 m_steps 创建的元素是非元素(通过)、失败或错误。
[XmlRoot("testsuite")]
public class Suite
{
[XmlAttribute("name")]
public string m_name;
[XmlElement("testcase")]
public List<Test> m_tests;
[XmlIgnore]
public string m_timestamp;
public class Test
{
[XmlAttribute("name")]
public string m_name;
[XmlElement("failure")] // want to be ignore, failure or error instead of just failure
public List<Step> m_steps;
[XmlAttribute("assertions")]
public int m_assertions;
}
public class Step
{
[XmlIgnore]
public string m_failure; // holds passed, failure, or error
[XmlTextAttribute]
public string m_message;
[XmlIgnore]
public string m_image;
[XmlAttribute("type")]
public string m_type;
}
寻找:
至:
<?xml version="1.0" encoding="UTF-8"?>
-<testsuite name=" SimpleCalculationsSuite" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-<testcase name="Add 3+4" assertions="1"></testcase>
-<testcase name="Fail 3-4" assertions="1">
<failure type="Text">The control text is not correct. Expected-7 Actual--1</failure>
</testcase>
-<testcase name="Error 3*4" assertions="1">
<error type="Click">The * button was not found</error>
</testsuite>
从:
Suite: SimpleCalculationsSuite
Test:Add 3+4
Passed:Text:The control text, 7, is correct.
Test:Fail 3-4
Failed:Text:The control text is not correct. Expected-7 Actual--1
Test:Error 3*4
Error:Click: The * button was not found