相关疑难解决方法(0)

MSTest和app.config问题

我试图通过MSTest和app.config的部署来自动运行单元测试.我阅读了多个帖子和博客,尝试了多项内容,但在MSTest执行期间,似乎仍然没有选择app.config.有一个包含我用msbuild构建的所有单元测试的dll,这是我试过的...

尝试1

  1. 将app.config复制到MyTests.dll作为MyTests.dll.config的同一位置(在其中一个msdn论坛上,它被称为自动拾取)
  2. [DeploymentItem("MyTests.dll.config")]为每个测试添加了属性
  3. MSTest.exe /noisolation /testcontainer:d:\MyTestTests.dll /test:MyTest

尝试2

  1. 创建具有以下内容的local.testrunco​​nfig文件(如下)
  2. 使用/ runco​​nfig执行mstest并且没有隔离,但没有执行任何操作: MSTest.exe /runconfig:d:\local.testrunconfig /testcontainer:d:\MyTestTests.dll /test:MyTest

结果: 正在加载d:\ local.testrunco​​nfig ...
d:\ local.testrunco​​nfig
d:\ local.testrunco​​nfig

......没有任何反应:没有错误,没有执行任何测试!


编辑/解决方案:默认情况下,MSTest在单独的进程中执行测试.在这种情况下,如果配置文件的名称类似于"dllname.dll.config",则会自动获取配置文件.但是,如果在VS之外运行,则很难调试在单独进程中运行的测试./ noisolation开关用于使MSTest在一个进程中运行所有测试.但是,在这种情况下,不会选择测试配置文件.而是使用MSTest.exe.config文件,该文件与MSTest位于同一目录中.要解决此问题,可以像下面这样实际加载配置文件:


ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"path to config file";
Configuration config = 
   ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
Run Code Online (Sandbox Code Playgroud)

c# msbuild mstest app-config

34
推荐指数
2
解决办法
2万
查看次数

标签 统计

app-config ×1

c# ×1

msbuild ×1

mstest ×1