MSTest and app.config issue

后端 未结 3 1906
粉色の甜心
粉色の甜心 2020-12-14 14:59

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

相关标签:
3条回答
  • 2020-12-14 15:43

    Your application doesn't use app.config. It uses application.exe.config. That's what you need to deploy.


    Sorry, didn't see you were testing a DLL.

    This is not how .NET configuration works. Each DLL does not use its own config file. It can only use the config file of the .exe it is running in (actually, of the AppDomain it's running in).

    You would somehow need to get MSTEST to add your .dll.config to its own configuration, assuming it's actually the host process. I don't see how to do that from the command line.

    I usually use a Unit Test Project in Visual Studio, so I just deploy the config file from that project. Works fine.

    0 讨论(0)
  • 2020-12-14 15:46

    The problem is, as it turns out, with our over-complicated build environment and the fact that we are using and x-copiable version of MSTest (produced locally). The following command succeeded when I ran against VS2008 "proper" MSTest:

    "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" /testcontainer:d:\MyTests.dll /test:MyTests /resultsfile:results.trx

    Thanks everyone for the answers! The check goes to you, Marius, you made me learn new things with your tesrunconfig.

    0 讨论(0)
  • 2020-12-14 15:48

    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>
    
    
    
    0 讨论(0)
提交回复
热议问题