开发者

WAP + NUnit + WebConfigurationManager Pin

I just started using NUnit to write test cases for my asp.net web application project.

Some of the code written to access database values fetches the ConnectionString from a "section" defined under "configSections" of web.config file.

This works fine during the normal execution of the project on a web browser. But when I access the same method through the test case, WebConfigurationManager.GetSection() always return null.

Initially I was also not able to access AppSettings section of web.config but it got s开发者_Go百科olved when I copied the web.config file into the BIN folder. But still not able to fetch the "section" inside "ConfigSection".

Kindly suggest.


By default NUnit will look for a config file that has the same name as the dll that contain the tests. So if you have someTests.dll NUnit will want to pick up someTests.dll.config. So for standard exes the trick is to copy your App.config to match the dll name pattern. I think that also works for web apps. You would copy web.config to someTests.dll.config. But to be honest I usually don't write tests that need to get to the config so I don't know for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜