如何协调 ASP.NET MVC 3 应用程序和 SpecFlow 之间的设置?

发布于 2024-11-18 23:45:16 字数 475 浏览 5 评论 0原文

因此,我有一个 VS 2010 解决方案,其中包含一个 ASP.NET MVC 3 项目和一个 SpecFlow 项目(使用 NUnit 作为测试运行程序)来测试前者。在 SpecFlow 下进行测试时(通过运行 SpecFlow 项目),我想更改 MVC 应用程序的 ConfigurationManager.AppSettings 字典中的参数,以使其连接到测试数据库。然而,此更改似乎不会影响正在运行的应用程序,因此我猜测试和应用程序不共享状态。

如何在 MVC 应用程序项目和 SpecFlow 项目之间共享此应用程序设置,以便它们使用相同的数据库?

编辑: 我发现问题实际上并不是项目(MVC 和 SpecFlow)之间共享设置的问题,而是两个进程之间的共享设置问题。原因是我通过 WatiN 测试 MVC,这意味着开发服务器正在其自己的进程中运行,正在通过测试进行测试。因此,我原来问题的前提从一开始就是错误的,考虑到原来的前提,我认为杰森的回答是有效的。

So I have a VS 2010 solution containing one ASP.NET MVC 3 project and one SpecFlow project (with NUnit as test runner) to test the former. When testing under SpecFlow (by running the SpecFlow project), I'd like to change a parameter in the MVC application's ConfigurationManager.AppSettings dictionary, to make it connect to a test database. This change does not seem to affect the running app however, so I guess the test and the app do not share state.

How can I share this application setting between the MVC app project and the SpecFlow project, so they use the same database?

Edit:
I found that the problem wasn't really one of sharing settings between projects (MVC and SpecFlow), but rather between two processes. The reason is that I test MVC via WatiN, which means that the development server, running in a process of its own, is being exercised by the tests. As such the premise of my original question was wrong from the onset, and I consider Jason's answer valid given the original premise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

老街孤人 2024-11-25 23:45:16

在您的测试项目 (SpecFlow) 中创建一个新的 app.config(除非它已经存在)并向其中添加 appSettings 部分以及您的测试数据库连接字符串。 IIRC 网站有望从测试项目的 appSettings 中获取连接字符串,而不是网站。

In your test project (SpecFlow) create a new app.config (unless it's already there) and add the appSettings section to that, with your test database connection string. IIRC the website will hopefully pick up the connection string from the appSettings of the test project, rather then the website.

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