mardi 31 mars 2015

How to refer to the datasource directory in MS Visual Studio unit test?

I have created an App.config file in the MS Visual Studio. The content of the App.config file is as below:



<?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="MyExcelConn" connectionString="Dsn=Excel Files;dbq=TestCases\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="TestData$" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
</configuration>


I have created a folder named "TestCases" in the same directory as the App.config file. I put the data.xlsx file inside the TestCases folder. For your information, data.xlsx is the data source of my unit tests. I coded the directory of the data source as TestCases\data.xlsx but it doesn't work. I don't want to hard code it as "C:\User...." as this would require me to change the code if I wish to run the code on another computer. Any suggestions?


Aucun commentaire:

Enregistrer un commentaire