单元测试的 Web.Config 问题
我正在尝试对很多 MVC 控制器进行单元测试,但不幸的是它一直失败,因为它需要 web.config 中的大量设置..
我复制了但没有读取它,我需要的是成员资格和 rolemanager,但我也不能将其添加到 app.config 中,我已经能够获取要使用的连接字符串和应用程序设置。
知道如何让 web.config 与 MSTest 一起使用吗?
I am trying to unit test a lot of my MVC controllers, but unfortunately it keeps failing because it needs a lot of settings from the web.config..
Which I copied over but does not read it, what I'm needing is the membership and rolemanager but I can't just add it to the app.config either, which I've been able to get the connection strings and application settings to work with..
Any idea how to get the web.config to work with MSTest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘲笑它
http://www.asp.net/learn/mvc-videos/ video-365.aspx
Mock it
http://www.asp.net/learn/mvc-videos/video-365.aspx
这个问题的一半已经在另一篇文章中得到了回答 - 在没有 ASP.NET 的情况下测试会员提供程序< /a>.应该可以使用相同的范例来测试角色管理器。
注意:我认为,要求通过配置文件检索设置(包括 asp.net 成员资格和角色管理器提供程序)以执行测试意味着您正在编写集成测试而不是单元测试。
Half of this question has already been answered in another post - Testing Membership provider without ASP.NET. Testing the rolemanager should be possible using the same paradigm.
Note: requiring settings (including the asp.net membership and rolemanager providers) to be retrieved via a config file for test execution means you are writing integration tests instead of unit tests my opinion.