MSTest的和发出的app.config [英] MSTest and app.config issue

查看:328
本文介绍了MSTest的和发出的app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困试图自动化单元测试MSTest的和app.config中部署运行。我看了多个帖子和博客,试图多件事情,但仍然app.config中似乎并不MSTest的执行过程中被拾起。具有包含内置的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 /测试:MyTest的



具有以下内容(如下图)尝试2




  1. 创建local.testrunco​​nfig文件

  2. 冉MSTest的使用/ runco​​nfig和无隔离,但没有被执行: MSTest.exe /runco​​nfig:d:\local.testrunco​​nfig /testcontainer:d:\MyTestTests.dll /测试: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地图=新ExeConfigurationFileMap();
map.ExeConfigFilename = @路径配置文件;
配置配置=
ConfigurationManager.OpenMappedExeConfiguration(地图,ConfigurationUserLevel.None);


解决方案

Kateroh,



我的设置是这样的(我用的MSBuild从TFSbuild.proj):




  1. 构建SLN


  2. 所有的输出到%TEMP%(魔法:D)复制
    不知道为什么,但MSTest的是寻找参考% 。TEMP%


  3. 与PARMS运行MSTest的:





C:\Program Files\Microsoft的Visual Studio 10.0\Common7\IDE\MSTest.exe/ NOLOGO / testcontainer:$(TESTDIR)\mylib .dll文件/ resultsfile:$(TestResultFile)/runco​​nfig:$(SlnDir)\AutomaticBuildTest.testrunco​​nfig / searchpathroot:$(TESTDIR)/发布:mytfsserver / publishbuild:$(BuildDefinition)/味:调试/平台:值为anycpu / teamproject: mytfsproject



其中AutomaticBuildTest.testrunco​​nfig为波纹管

 

< XML版本=1.0编码=UTF-8>?;
< TestSettings NAME =AutomaticBuildTestID =eda99352-93e1-402e-9517-d04fffa66b35的xmlns =htt​​p://microsoft.com/schemas/VisualStudio/TeamTest/2010>
<! - <部署启用=FALSE/> - >
<启用部署=真正的>
< D​​eploymentItem名=D:\sa12\78\bin\Debug/>
< /部署>
< NamingScheme baseName的=BC2ALibraryTestappendTimeStamp =假useDefault =FALSE/>
<! - http://blogs.msdn.com/b/vstsqualitytools/archive/2009/12/01/executing-unit-tests-in-parallel-on-a-multi-cpu-core -machine.aspx - >
<执行位置=本地hostProcessPlatform =MSIL>
< --http://msdn.microsoft.com/en-us/library/ms404663.aspx-->
< ExecutionThread的ApartmentState =MTA/>
<主机skipUnhostableTests =FALSE/>
< TestTypeSpecific>
< UnitTestRunConfig testTypeId =13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b>
< AssemblyResolution applicationBaseDirectory =D:\sa12\78\bin\Debug>
< TestDirectory useLoadContext =FALSE/>
< / AssemblyResolution>
< / UnitTestRunConfig>
< / TestTypeSpecific>
< AgentRule NAME =LocalMachineDefaultRole>
< / AgentRule>
< /执行>
< / TestSettings>



I am stuck trying to automate unit tests runs with MSTest and deployment of app.config. I read multiple posts and blogs, tried multiple things and yet still app.config doesn't seem to be picked up during MSTest execution. Having a dll that contains all my unit tests built with msbuild, here is what I've tried...

Attempt 1

  1. Copied app.config to the same location with MyTests.dll as MyTests.dll.config (on one of the msdn forums it was said it'd be picked up automagically)
  2. Added [DeploymentItem("MyTests.dll.config")] attribute to each test
  3. Ran MSTest.exe /noisolation /testcontainer:d:\MyTestTests.dll /test:MyTest

Attempt 2

  1. Created local.testrunconfig file with the following content (below)
  2. Ran mstest with /runconfig and no isolation, but nothing was executed: MSTest.exe /runconfig:d:\local.testrunconfig /testcontainer:d:\MyTestTests.dll /test:MyTest

Result: Loading d:\local.testrunconfig...
d:\local.testrunconfig
d:\local.testrunconfig

... and nothing happens: no errors, no tests are executed!


EDIT/RESOLUTION: By default, MSTest executes tests in separate processes. In this case, config file is automatically picked up if it is named like "dllname.dll.config". However, it is hard to debug tests running in separate processes if they run outside of VS. /noisolation switch is used to make MSTest run all tests in one process. However, in this case test config file is NOT picked up. Instead, MSTest.exe.config file is used, which is located in the same directory as MSTest. To resolve this issue, configuration file can be loaded pragmatically like this:


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

解决方案

Kateroh,

My setup looks like this (I'm using msbuild from a TFSbuild.proj):

  1. Build sln

  2. Copy all from output to %TEMP% (black magic :D) Don't know why but mstest is looking for references in %TEMP%.

  3. Run mstest with parms:

"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /nologo /testcontainer:$(TestDir)\mylib.dll /resultsfile:$(TestResultFile) /runconfig:$(SlnDir)\AutomaticBuildTest.testrunconfig /searchpathroot:$(TestDir) /publish:mytfsserver /publishbuild:$(BuildDefinition) /flavor:Debug /platform:AnyCPU /teamproject:mytfsproject

where AutomaticBuildTest.testrunconfig is bellow


<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="AutomaticBuildTest" id="eda99352-93e1-402e-9517-d04fffa66b35" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
    <!--<Deployment enabled="false" />-->
    <Deployment enabled="true">
        <DeploymentItem filename="D:\sa12\78\bin\Debug" />
    </Deployment>
    <NamingScheme baseName="BC2ALibraryTest" appendTimeStamp="false" useDefault="false" />
    <!-- http://blogs.msdn.com/b/vstsqualitytools/archive/2009/12/01/executing-unit-tests-in-parallel-on-a-multi-cpu-core-machine.aspx -->
    <Execution location="Local" hostProcessPlatform="MSIL">
        <!--http://msdn.microsoft.com/en-us/library/ms404663.aspx-->
        <ExecutionThread apartmentState="MTA" />
        <Hosts skipUnhostableTests="false" />
        <TestTypeSpecific>
            <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
                <AssemblyResolution applicationBaseDirectory="D:\sa12\78\bin\Debug">
                    <TestDirectory useLoadContext="false" />
                </AssemblyResolution>
            </UnitTestRunConfig>
        </TestTypeSpecific>
        <AgentRule name="LocalMachineDefaultRole">
        </AgentRule>
    </Execution>
</TestSettings>


这篇关于MSTest的和发出的app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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