3

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ことに注意してください(ページ下部の注記による)。

編集:ああ、すべてのファイルは私のコンピューターのローカルにあります。

4

3 に答える 3

3

フルファイルパスを使用してみましたか?

ファイルは読み取り専用ですか?

于 2011-09-25T21:40:39.580 に答える
2

TestSettingsの一部としてデプロイするファイル/ディレクトリを指定することもできます。これにより、すべてのテストメソッドにDeploymentItem属性を設定する手間が省けます。

于 2011-11-08T07:29:47.027 に答える
1

後に構成を使用します。

<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>
于 2012-03-28T16:08:28.470 に答える