我有一個使用實體框架的應用程序。我正在編寫一個單元測試,我想從CSV文件中使用數據驅動的測試。數據驅動的單元測試打破實體框架連接
然而,當我運行測試,我得到一個錯誤的SQLSERVER提供商無法加載:
初始化方法UnitTest.CalculationTest.MyTestInitialize拋出 例外。 System.InvalidOperationException: System.InvalidOperationException:實體框架提供程序類型 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'在應用程序配置文件 中爲具有不變名稱System的ADO.NET提供程序註冊。無法加載Data.SqlClient' 。確保使用裝配限定名稱 ,並且裝配對於運行的應用程序可用。
- 如果我刪除了數據驅動的方面,只是測試單個值,那麼測試工作。
- 如果我只是使用數據驅動的方面,並刪除實體框架的東西,然後測試工作。
所以,它只有當我嘗試使用數據驅動測試與實體框架同時活動時,我會得到錯誤。那麼,我在哪裏錯了?
這裏是我的測試方法:
[TestMethod, TestCategory("Calculations")
, DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV"
, "ConvertedMeanProfileDepth.csv", "ConvertedMeanProfileDepth#csv"
, Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod.Sequential)
, DeploymentItem("ConvertedMeanProfileDepth.csv")]
public void ConvertedMeanProfileDepthTest()
{
ConvertedMeanProfileDepth target = new ConvertedMeanProfileDepth();
Decimal mpd = decimal.Parse(this.TestContext.DataRow["mpd"].ToString());
Decimal expected = decimal.Parse(this.TestContext.DataRow["converted"].ToString());
Decimal actual;
actual = target.Calculate(mpd);
Assert.AreEqual(expected, actual);
}