Connection strings not available from App.Config in Unit Tests run on TFS 2015 -
i'v db facing unit tests take connection string app.config file. i'm grabbing strings thru configurationmanager class.
var constring = configurationmanager.connectionstrings["db"].connectionstring;
the tests run fine on dev machine not on tfs. there null refernce error. if jsut replace connection string in unit test hard coded string - identical in app.config - test works. oh yeah, , i've made sure app.config set "copy output folder".
is there known issue tfs , configurationmanager?
pom
i ran same problem tfs 2015 (on premises update 2). have multiple test projects access connection string app.config file 1 particular project failed access connection string caused our build fail.
i altered .csproj file match other working test projects didn't provide success, instead following worked me:
- copied contents of app.config notepad
- deleted app.config file project
- added new application configuration file (app.config) project
- pasted contents notepad new app.confg file
- right click app.config file , altered properties:
- build action: content
- copy output directory: copy always
upon check-in unit tests within project passed successfully.
it's odd solution got our tests running.
note: deleting app.config file necessary step. changing properties on file (prior deleting file) didn't make difference.
update:
after applying above solution noticed unit tests running twice , after investigation discovered entire issue down our build configuration: -
on our visual studio build task use following parameter on our ms build arguments:
/p:outdir=$(build.stagingdirectory)
our visual studio test task configured test assembly in following location:
**\$(buildconfiguration)\*test*.dll;-:**\obj\**
altering test assembly location following fixed everything:
$(build.stagingdirectory)\*test*.dll;-:**\_publishedwebsites\**
no more issues app.config files , unit tests ran once only.
Comments
Post a Comment