如何在 NUnit 中初始化 ConnectionStrings 集合 [英] How to initialize ConnectionStrings collection in NUnit

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

问题描述

我想使用 NUnit 测试 ASP.NET 应用程序,但是从 NUnit GUI 运行时,WebConfigurationManager.ConnectionStrings 集合似乎是空的.

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

你能告诉我如何初始化这个集合吗(可能在 [TestFixture] 的 [SetUp] 函数中)?我应该在那里复制 Web.config 吗?

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天全站免登陆