[TestMethod]
public void TestDerpMethod(int a, string b, bool c)
{
//...test code...
}
你可以做多個測試用例,像這樣:
<Rows>
<Row>
<A1>1</A1>
<A2>1</A2>
<Result>2</Result>
</Row>
<Row>
<A1>1</A1>
<A2>2</A2>
<Result>3</Result>
</Row>
<Row>
<A1>1</A1>
<A2>-1</A2>
<Result>1</Result>
</Row>
</Rows>
和C#:
[TestMethod]
[TestCase(12, "12", true)]
[TestCase(15, "15", false)]
public void TestDerpMethod(int a, string b, bool c)
{
//...test code...
}
您也可以使用此方法使用此方法XML
[TestMethod]
[DeploymentItem("ProjectName\\SumTestData.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"|DataDirectory|\\SumTestData.xml",
"Row",
DataAccessMethod.Sequential)]
public void SumTest()
{
int a1 = Int32.Parse((string)TestContext.DataRow["A1"]);
int a2 = Int32.Parse((string)TestContext.DataRow["A2"]);
int result = Int32.Parse((string)TestContext.DataRow["Result"]);
ExecSumTest(a1, a2, result);
}
private static void ExecSumTest(int a1, int a2, int result)
{
Assert.AreEqual(a1 + a2, result);
}
希望這將有助於FUL
參考此鏈接
http://sylvester-lee.blogspot.in/2012/09/data-driven-unit-testing-with-xml.html
也
http://social.msdn.microsoft.com/Forums/vstudio/en-US/7f6a739a-9b12-4e8d-ad52-cdc0ca7a2752/using-xml-datasource-in-unit-test
爲什麼要在XML中定義測試? – Steven
它們可能是兩個或更多的測試用例,現在我們在xml文件中給出輸入數據。 – kumar