无线应用协议NUnit + WebConfigurationManager 引脚

发布于 2024-08-08 12:17:13 字数 364 浏览 4 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-08-15 12:17:13

默认情况下,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文