无线应用协议NUnit + WebConfigurationManager 引脚
我刚刚开始使用 NUnit 为我的 asp.net Web 应用程序项目编写测试用例。
一些为访问数据库值而编写的代码从 web.config 文件的“configSections”下定义的“部分”获取 ConnectionString。
在 Web 浏览器上正常执行项目期间,这可以正常工作。但是当我通过测试用例访问相同的方法时,WebConfigurationManager.GetSection() 总是返回 null。
最初我也无法访问 web.config 的 AppSettings 部分,但当我将 web.config 文件复制到 BIN 文件夹中时,问题得到了解决。但仍然无法获取“ConfigSection”内的“部分”。
请建议。
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 solved when I copied the web.config file into the BIN folder. But still not able to fetch the "section" inside "ConfigSection".
Kindly suggest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,NUnit 将查找与包含测试的 dll 同名的配置文件。因此,如果您有 someTests.dll,NUnit 将需要获取 someTests.dll.config。因此,对于标准 exe,技巧是复制 App.config 以匹配 dll 名称模式。我认为这也适用于网络应用程序。您可以将 web.config 复制到 someTests.dll.config。但说实话,我通常不会编写需要访问配置的测试,所以我不确定。
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.