0

I have written a data-driven unit test and now I need to specify the data source for the unit test. The unit test is written in C# with MS Visual Studio. My data source is an excel file with a sheet named "TestData". My code for data source is as follows:

[DataSource(
        "System.Data.Odbc",
        "Dsn=Excel Files;dbq=.\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5",
        "TestData$",
        "Sequential"
    )]

What's wrong and how to fix it?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Mary June
  • 139
  • 4
  • 19
  • What's your problem with this? Raise any error? [DataSourceAttribute Class](https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.datasourceattribute.aspx) – Peyman Apr 08 '15 at 05:14
  • That doesn't meet the constructor of DataSource. However, I found this [DataSource( dataProvider, connectionString, tableName, dataAccessMethod )] at https://msdn.microsoft.com/en-us/library/ms182527.aspx#bkmk_creating_a_data_source – Mary June Apr 08 '15 at 05:18
  • This question has already been resolved. Please refer, http://stackoverflow.com/questions/22538340/data-driven-unit-test-from-excel-spreadsheet – Shyju Apr 08 '15 at 05:21

2 Answers2

1

You can put ConnectionString in Config file and add to Attribute

<connectionStrings>  
     <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=.\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />  
</connectionStrings>

Then add to your update your attribute:

[DataSource("MyExcelDataSource")]
Peyman
  • 3,068
  • 1
  • 18
  • 32
0

You need to run Visual Studio Data Source Wizard to run the tests. Click here to See the Youtube Video

vibs2006
  • 6,028
  • 3
  • 40
  • 40