Data Driven Unit Test Problem

I'm having trouble setting up my unit tests to use an Excel.xlsx data source.

My App.config file:

<?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> 

I checked that it finds TestData.xlsx , and there is a sheet called GetAllCellNamesTest .

In my unit test class, I have the following setup:

  [TestMethod()] [DeploymentItem("TestProject\\TestData.xlsx")] [DataSource("GetAllCellNamesTest")] public void GetAllCellNamesTest() { // ... test code 

TestData.xlsx copied to the test results catalog, and all unit tests that do not attempt to reference the data source are transferred.

However, this test does not work with the following message:

 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. 

I'm really not sure where my setup is wrong, I followed this walkthrough on MSDN to get the setup: Walkthrough. Use a configuration file to determine the data source . Note that I changed the section version to 10.0.0.0 because I am using .net 4.0 (in the note at the bottom of the page).

edit: oh, and all the files are locally located on my computer.

+3
c # unit-testing visual-studio-2010 data-driven-tests
source share
3 answers

Have you tried to use the full path to the file?

Is the file read-only?

+3
source share

You can also specify the files / directory that you want to deploy as part of the test suites. This eliminates the need to add a DeploymentItem attribute for each test method.

+2
source share

you use the configuration after;

 <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> 
+1
source share

All Articles