我试图通过MSTest和app.config的部署来自动运行单元测试.我阅读了多个帖子和博客,尝试了多项内容,但在MSTest执行期间,似乎仍然没有选择app.config.有一个包含我用msbuild构建的所有单元测试的dll,这是我试过的...
[DeploymentItem("MyTests.dll.config")]为每个测试添加了属性MSTest.exe /noisolation /testcontainer:d:\MyTestTests.dll /test:MyTestMSTest.exe /runconfig:d:\local.testrunconfig /testcontainer:d:\MyTestTests.dll /test:MyTest结果:
正在加载d:\ local.testrunconfig ...
d:\ local.testrunconfig
d:\ local.testrunconfig
......没有任何反应:没有错误,没有执行任何测试!
编辑/解决方案:默认情况下,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)