如何使用的web.config时单元测试的ASP .NET应用程序 [英] How to use web.config when unit testing an asp .net application

查看:218
本文介绍了如何使用的web.config时单元测试的ASP .NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始接触单元测试,我有一个使用web.config中的连接字符串的方法。

I am starting out with unit testing, I have a method that uses the web.config for a connection string.

我希望能够使用

[DeploymentItem("web.config")]

要获得网络配置文件,这仍然给我留下空引用异常(这会是我写的东西我的下一个测试)。

to get the web config file, this still leaves me with null reference exceptions (that'd be what I write my next test for).

我如何使用配置文件中包含的项目,我想测试?

How do I use the config file included with the project I am trying to test?

我使用包含在VS 2008的测试框架,如果有什么差别。

I am using the testing framework included in VS 2008, if that makes any difference.

感谢

推荐答案

单元测试的项目都应该有自己的配置文件。

Unit test projects should have their own config file.

在一个测试项目,你可以选择添加,新项,应用程序配置文件。

On a test project you can choose Add, New Item, Application Configuration File.

此文件的行为完全像一个web.config,但随后的单元测试。

This file will behave exactly like a web.config, but then for your unit tests.

这篇关于如何使用的web.config时单元测试的ASP .NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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