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


i have created app.config file in ms visual studio. content of app.config file 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 folder named "testcases" in same directory app.config file. put data.xlsx file inside testcases folder. information, data.xlsx data source of unit tests. coded directory of data source testcases\data.xlsx doesn't work. don't want hard code "c:\user...." require me change code if wish run code on computer. suggestions?

there few options

  1. this easiest one. set [deploymentitem("yourexcelfile")] attribute on test class or test method, way can refer them config using relative path of .\yourexcelfile.

  2. this 1 harder, since mstest drops testresults folder in same location (relative solution) can use ..\..\..\..\project\yourexcelfile path it. beware, tfs' team build may use different relative path , before know need trickery in build system work.

  3. copy excel file wellknown location, c:\testsources\mydatasource , map file location using tfvc source control workspace setup. allow test configuration point full path, should able find.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -