vendredi 2 septembre 2016

C# Data-Driven Unit Test Change DataSource in Code

Is there a way to change the DataSource of a unit test in code? We'd like to have 2 different Excel files for 2 environments (QA and Prod), and depending on which environment, I'd like to change the DataSource of the unit test to read from the corresponding file.

I know I can configure the DataSource in app.config (and use config transform for the different environments), but am wondering if there's a different way since we have lots of tests and will end up with lots of these entries in app.config.

<add name="BinLookupConn" 
         connectionString="Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=|DataDirectory|\\TestInputData\\BinLookup.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true" providerName="System.Data.Odbc" />

Thanks!

Aucun commentaire:

Enregistrer un commentaire