如何初始化NUnit的收集的ConnectionStrings [英] How to initialize ConnectionStrings collection in NUnit

查看:117
本文介绍了如何初始化NUnit的收集的ConnectionStrings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用NUnit的测试ASP.NET应用程序,但它似乎WebConfigurationManager.ConnectionStrings从NUnit的图形界面运行时,集合为空。

I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is empty when running from NUnit GUI.

你能告诉我如何初始化此集合(可能在[可是TestFixture] [设定]功能)?我应该复制的Web.config somethere?

Could you tell me how to initialize this collection (probably in [SetUp] function of [TestFixture])? Should I copy Web.config somethere?

感谢您!

推荐答案

如果您有您的单元测试程序集命名Company.Component.Tests.dll,则只需确保Company.Component.Tests.dll.config有用适当的连接字符串。

If you have your unit-test assembly named Company.Component.Tests.dll, then just make sure that Company.Component.Tests.dll.config is there with the proper connection string.

此外,它可能是从配置中分离出的连接供应商类是一个好主意,这样你将有持久性的灵活性(即:从*的.config切换到别的东西),更容易测试。

Additionally, it might be a good idea to decouple your connection provider class from the configuration, so that you will have flexibility in persistence (i.e.: switching from *.config to something else) and easier testing.

另外,请查阅如何NUnit的查找配置文件

这篇关于如何初始化NUnit的收集的ConnectionStrings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆