App.config中的测试项目 [英] App.config in Test Projects
问题描述
我要建在VS2010一个ASP.NET应用程序。我有许多单独的组件(类库)和相应的测试项目,每一个。
I'm building an ASP.NET app in VS2010. I have a number of separate assemblies (class libraries) and corresponding Test projects for each.
在类库我使用一个app.config文件来存储设置。大会本身使用下列code检索设置:
In one of the class libraries I use an App.config file to store settings. The assembly itself uses the following code to retrieve settings:
string tmp = ConfigurationManager.AppSettings["mySetting"];
现在的问题是,当我尝试创建一个单独的测试项目中的单元测试,测试不拿起在App.config文件中的设置。如果我复制App.config文件到测试项目,它的工作原理。
The problem is that when I try to create a Unit Test in a separate test project, the test does not pick up the setting in the App.config file. If I COPY the App.config file into the Test project, it works.
我怎么能保证每个组件都使用自己的App.config文件的副本。这会带来问题,如果我不得不四处复制配置文件。还有另外一个问题,因为可能有多个配置文件,每个装配体中一个 - 他们怎么可能都共存于一个单一的测试项目反正
How can I ensure that each assembly uses its own copy of an App.config file. It would introduce problems if I had to copy config files around. There's an additional problem because there may be multiple config files, one per assembly - how could they all co-exist in a single test project anyway?
谢谢!
推荐答案
好吧,如果你需要的的App.config 的跨多个项目共享的文件,我想简单地添加为链接原的App.config 的每个项目中的文件。
Well, if you need a App.config file shared across several projects, I would simply "Add as Link" the original App.config file in each project.
让我们假设你有项目A 与原来的的App.config 的。然后你有 ProjectATest1 和 ProjectATest2 。在每个的 TestX 的项目:
Let's say you have ProjectA with the original App.config. Then you have ProjectATest1 and ProjectATest2. In each of the TestX project:
- 右键单击在Visual Studio 解决方案名称
- 选择添加现有项
- 导航到项目A 的App.config 的,并选择它
- 单击添加按钮向下箭头
- 选择添加为链接
- right click on the solution name in Visual Studio
- select "Add Existing Item"
- navigate to the ProjectA App.config and select it
- click in the "Add" button down arrow
- select "Add as Link"
这将创建一个的App.config 的快捷方式中的每个的 TestX 的项目。如果你改变它,它会改变无处不在。
It'll create a App.config shortcut in each TestX project. If you change it, it will change everywhere.
希望这有助于。
这篇关于App.config中的测试项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!