如何为MS Test项目设置工作目录 [英] How to set the working directory for MS Test projects

查看:65
本文介绍了如何为MS Test项目设置工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为MS Tests项目设置工作目录,就像可以为普通应用程序项目设置工作目录一样?经过测试的我的组件需要访问一些其他应用程序也使用的配置文件.到目前为止,我必须将这些文件复制到测试项目的bin/debug文件夹中,因为这些文件应该位于工作目录中.

how can I set the working directory for MS Tests projects, like I can do it for normal application projects? My Component that is tested need to access some config files that are also used by other applications. So far I have to copy these files the bin/debug folder of my test project, as these files are expected to be in the working directory.

是否可以为测试项目设置工作目录?

Is it possible to set a working directory for test projects?

推荐答案

对于使用Visual Studio 2012的用户,如果将测试项目的输出目录设置为Properties | Build | OutputPath,那么当您使用该目录时,它将成为工作目录.从Visual Studio运行测试(因为它使用的是Vstest.console.exe).如果您不想将测试dll等输出到其他文件所在的目录,并且不想将其他文件作为测试项目中的内容(如Schaliasos的建议),则可以设置具有[AssemblyInitialize]属性的方法中启动时的路径.通过照常分配System.Environment.CurrentDirectory来执行此操作.您可能希望将工作目录作为设置或从配置文件中读取.

For those who use Visual Studio 2012, if you set the output directory of the test project under Properties|Build|OutputPath then that will become the working directory when you run the tests from Visual Studio (since it is using Vstest.console.exe). If you don't want to have your test dlls, etc output to the same directory as your other files and you don't want to have the other files as content in your test project (as suggested by Schaliasos) then you can set the path on startup in a method that has the [AssemblyInitialize] attribute. You do this by assigning System.Environment.CurrentDirectory as usual. You will probably want to have the working directory as a setting or read from a configuration file.

修改

如Rohit.Net所指出的那样,当您选择Run All Tests时,默认路径将位于TestResults下.使用runsettings文件时也是如此.当您不使用DeploymentItems时,输出文件夹将是默认的工作目录,并且:-

As pointed out by Rohit.Net, when you choose Run All Tests the default path would be under TestResults. The same applies when using a runsettings file. The output folder will be the default working directory when you are not using DeploymentItems and: -

  • 您右键单击Visual Studio中的测试,然后选择运行/调试,或者
  • 您使用vstest.console.exe从命令行运行.

这篇关于如何为MS Test项目设置工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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