我與下面鏈接的問題具有基本相同的問題,但似乎無法使其工作。我得到「不能將索引[]應用於System.Data.DataRow類型的表達式」。據我所知,我已經正確實施瞭解決方案。MSTest中的數據驅動測試 - TestContext.DataRow問題
Problems with data driven testing in MSTest
[TestClass]
public class UnitTest1
{
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
private ServiceReference1.ProductCatalogClient client = new ServiceReference1.ProductCatalogClient("BasicHttpBinding_IProductCatalog");
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\CountList.csv", "CountList#csv", DataAccessMethod.Sequential), DeploymentItem("..\\ServiceTest\\CountList.csv"), TestMethod]
public void AreCountsCorrect()
{
int id = TestContext.DataRow["Id"] as int;
int count = client.GetProductCount(id);
Assert.IsTrue(count == TestContext.DataRow["Count"] as int);
}
}
發現我的問題:需要在我的測試項目中添加對System.Data的引用。 – bq1990 2011-01-25 03:47:51