我有一个调用 2 个子测试方法的测试方法。这两个子方法都是从 XML 文件中驱动的数据。如果我运行每个子方法,它们运行良好且成功。但是,当我运行主测试方法(两个子方法的调用者)时,它发现 TestContext.DataConnection 和 TestContext.DataRow 为空。
private TestContext testContext;
public TestContext TestContext
{
get { return testContext; }
set { testContext = value; }
}
[TestMethod]
public void SaveEmpty_Json_LocalStorage()
{
// Testing JSON Type format export and save
SetWindowsUsers();
// Add Network Information
SetWifiInformation();
// More logic and assertions here.
// More logic and assertions here.
// More logic and assertions here.
}
[TestMethod]
[DeploymentItem("input.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"input.xml",
"User",
DataAccessMethod.Sequential)]
public void SetWindowsUsers()
{
Console.WriteLine(TestContext.DataRow["UserName"].ToString())
// MORE LOGIC and Asserts
}
[TestMethod]
[DeploymentItem("input.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
"input.xml",
"WifiList",
DataAccessMethod.Sequential)]
public void SetWifiInformation()
{
Console.WriteLine(TestContext.DataRow["SSID"].ToString())
// MORE LOGIC and Asserts
}
如果我全部运行,则 2 个方法通过,1 个失败。如果我单独运行, SaveData_Json_LocalStorage 不会通过,总是将 TestContext.DataRow 设为 null。里面调用多个方法可以吗。编写链式测试用例的最佳方法是什么。