[英]Data driven unit tests problem
我有一些麻煩讓我的單元測試設置為使用Excel .xlsx數據源。
我的App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="TestData" connectionString="Dsn=Excel Files;dbq=TestData.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="GetAllCellNamesTest" connectionString="TestData" dataTableName="GetAllCellNamesTest$" dataAccessMethod="Sequential"/>
</dataSources>
我已經驗證它正在查找TestData.xlsx
,並且有一個名為GetAllCellNamesTest
的工作表。
在我的單元測試類中,我有以下設置:
[TestMethod()]
[DeploymentItem("TestProject\\TestData.xlsx")]
[DataSource("GetAllCellNamesTest")]
public void GetAllCellNamesTest()
{
// ... test code
TestData.xlsx
正被復制到測試結果目錄,並且所有不嘗試引用數據源的單元測試都將被傳遞。
但是,這一個測試失敗,並顯示以下消息:
The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.
Error details: ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Access database engine could not find the object 'GetAllCellNamesTest$'. Make sure the object exists and that you spell its name and the path name correctly. If 'GetAllCellNamesTest$' is not a local object, check your network connection or contact the server administrator.
我真的不確定我的設置在哪里出錯了,我在MSDN上按照這個演練來進行設置: 演練:使用配置文件來定義數據源 。 請注意,我確實將section
版本更改為10.0.0.0
因為我使用的是.net 4.0(根據頁面底部的注釋)。
編輯:哦,所有文件都位於我的計算機本地。
您是否嘗試過使用完整的文件路徑?
該文件是只讀的嗎?
您還可以指定要作為TestSettings的一部分部署的文件/目錄。 這將節省您必須為每個測試方法放置DeploymentItem屬性的工作量。
你之后使用配置;
<configSections>
<section name="microsoft.visualstudio.testtools"
type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection,
Microsoft.VisualStudio.QualityTools.UnitTestFramework,
Version=10.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.