如何协调 ASP.NET MVC 3 应用程序和 SpecFlow 之间的设置?
因此,我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的测试项目 (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 theappSettings
of the test project, rather then the website.