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
はテスト結果ディレクトリにコピーされており、データソースを参照しようとしないすべての単体テストに合格しています。
ただし、この1つのテストは失敗し、次のメッセージが表示されます。
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
.net 4.0を使用しているため、バージョンをに変更した10.0.0.0
ことに注意してください(ページ下部の注記による)。
編集:ああ、すべてのファイルは私のコンピューターのローカルにあります。