我有一个测试方法,它调用2个子测试方法.子方法都是从XML文件驱动的数据.如果我运行每个子方法,它们运行良好且成功.但是,当我运行主测试方法(两个子方法的调用者)时,它发现TestContext.DataConnection和TestContext.DataRow为null.
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", …Run Code Online (Sandbox Code Playgroud)