如何测试我所有的期望web.config设置已经确定? [英] How do I test that all my expected web.config settings have been defined?

查看:178
本文介绍了如何测试我所有的期望web.config设置已经确定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是内置在VS2008测试框架,我想能够写一个测试,确保所有预期的web.config设置已经确定,这样,如果偶然一个删除或改变了我的测试套件将检测到它并没有在运行时情形进行测试。我将如何设置呢?

I am using the built in test framework in VS2008 and I would like be able to write a test that makes sure all the expected web.config settings have been defined so that if by accident one is removed or changed my suite of tests will detect it and not have to be tested in a runtime scenario. How would I set this up?

我不想设置我的web.config的样机,因为我不想维护两个版本,这将使我的测试反正无效,因为我真的想捕捉一个事实,即该项目的web.config是正确的。

I do not want to setup a mockup of my web.config since I don't want to maintain two versions and this would make my test invalid anyways since I am really trying to capture the fact that the project's web.config is correct.

任何建议,选择,提示吗?

Any suggestions, alternatives, hints?

解决方案:我结束了在该建议一个变革的pre-构建使用复制。在副本重新命名web.config中的app.config使得测试项目将自动把它捡起来。

Solution: I ended up using the copy in the pre-build that was suggested with one change. On copy I rename the web.config to app.config so that the test project would automatically pick it up.

我试图打出配置文件的建议很好,但我碰到的问题是,当测试项目跑了,但实际上并没有走出bin目录下运行(该配置文件设置为内容类型将复制到),而是以结果目录已定义pre。我无法弄清楚如何使它复制茨艾伦额外的文件到这个结果目录这样的配置文件可能永远不会被发现。

I tried to split out the config files as suggested as well but the problem I ran into was when the test project ran, it actually didn't run out of the bin directory (which setting the config files to 'Content' type would copy to) but instead to a results directory that has been pre defined. I could not figure out how to make it copy thos extra files to this results directory so the config files could never be found.

推荐答案

我'使用pre-生成事件对工作的web.config复制到您的测试项目目录。

I'am using the pre-build event to copy working web.config to your test project directory.

测试项目的pre-生成事件的命令行设置为这样的字符串:

Set the command line of the pre-build event of test project to string like this:

copy $(SolutionDir)\YourWebAppDir\web.config $(ProjectDir) /y

这之后你的测试将始终与实际的web.config版本上运行。

After that your tests will always run with actual web.config version.

注释<一个href=\"http://stackoverflow.com/questions/1561663/how-do-i-test-that-all-my-expected-web-config-settings-have-been-defined/1561883#1561883\">pcampbell's回答:

Comment to pcampbell's answer:

我想,如果你使用 configSource 属性你可以将其设置为相同的路径在您的网络应用和测试项目和app.config中的web.config文件使得没有必要使用生成事件。

I think if you use the configSource attribute you can just set it to the same path in web.config of your web app and app.config of test project and that makes not necessary to use build events.

对不起,我不能发表评论呢。

sorry, I can't leave comments yet.

这篇关于如何测试我所有的期望web.config设置已经确定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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