How to initialize ConnectionStrings collection in NUnit(如何在 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 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 NUnit 中初始化 ConnectionStrings 集合
基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
