locked
Can I specify app.config file with MSTest in VS2008 RRS feed

  • Question

  • I would like to be able to have my test code run in the context of one (or other) app.config files.

    How can I specify which config file MSTest is to use? Oh, by the way which one does it use by default?

     

    Friday, June 13, 2008 3:25 PM

Answers

  • Is this about Unit Tests? If you want to specify app.config for your unit test assembly:

    - In VS IDE: right click Test Project node in Solution Explorer -> Add New Item -> Applicaiton Configuration File

    - If you run tests from command line: put app.config file next to your test assembly. When we run tests, we will pick it up. If you have more than one test assembly, and you want different configuration for each test assembly, create .dll.config files for each test assemlby, such as TestAssembly1.dll.config, TestAssembly2.dll.config assuming that your test assemblies are TestAssembly1.dll, TestAssembly2.dll, and put the files to the same dir as test assemblies.

    - If you run tests from command line with /noisolation switch, you will have to modify mstest.exe.config which is in Common7\IDE (just next to mstest.exe) under VS installation dir.

     

    By default mstest does not use any .config file for unit test assembly (depending on whether you use /noisolation, either mstest.exe.config or vstesthost.exe.config is used).

     

    Thanks,

    Michael

    Friday, June 13, 2008 4:08 PM

All replies

  • Is this about Unit Tests? If you want to specify app.config for your unit test assembly:

    - In VS IDE: right click Test Project node in Solution Explorer -> Add New Item -> Applicaiton Configuration File

    - If you run tests from command line: put app.config file next to your test assembly. When we run tests, we will pick it up. If you have more than one test assembly, and you want different configuration for each test assembly, create .dll.config files for each test assemlby, such as TestAssembly1.dll.config, TestAssembly2.dll.config assuming that your test assemblies are TestAssembly1.dll, TestAssembly2.dll, and put the files to the same dir as test assemblies.

    - If you run tests from command line with /noisolation switch, you will have to modify mstest.exe.config which is in Common7\IDE (just next to mstest.exe) under VS installation dir.

     

    By default mstest does not use any .config file for unit test assembly (depending on whether you use /noisolation, either mstest.exe.config or vstesthost.exe.config is used).

     

    Thanks,

    Michael

    Friday, June 13, 2008 4:08 PM
  • what do I have to set up in mstest.exe.config?

    mine is:

    <?xml version ="1.0"?>
    <configuration>
        <runtime>
            <assemblyBinding xmlns="urnTongue Tiedchemas-microsoft-com:asm.v1">
                <probing privatePath="PrivateAssemblies;PublicAssemblies"/>
            </assemblyBinding>
        </runtime>
    </configuration>

    don´t know what to change in there. Sad

    I have the exact same problem and I am stuck in this.
    Wednesday, September 17, 2008 7:52 PM
  • Not sure what your question is.  Depending on how you run your tests, just follow Michael's suggestion (he gives you 3 ways of executing: VS, MSTest and MSTest /noisolation.

     

     

    Wednesday, September 17, 2008 8:51 PM
  • i use the the \runconfig option from mstest to execute my set of tests.

    so my mstest command is like this:

    mstest \testcontainer:<mytest.dll> \runconfig:<myconfig.
    testrunconfig>

    using that command, my test code runs fine.

    however, I use ncover to get my code coverage, and for the code coverage be gathered by the tool, I have to run my test in noisolation mode, so my mstest has to be:

    mstest \testcontainer:<mytest.dll> \runconfig:<myconfig.testrunconfig> \noisolation

    the thing is, when i use this option (
    \noisolation) and the \runconfig at the same time, mstest for some reason does not execute my test code. (he fails them all, because he throws an argument exeption....debugging the error, I checked that he thows the exeption in a part of the code that deals with file paths...).

    so all my problems would be resolved if i could sucessufly run this command

    mstest \testcontainer:<mytest.dll> \runconfig:<myconfig.testrunconfig> \noisolation

    im
    Michael´s thread he mentioned:

    "
    - If you run tests from command line with /noisolation switch, you will have to modify mstest.exe.config which is in Common7\IDE (just next to mstest.exe) under VS installation dir."

    that´s where i got stuck, i wonder what need´s to be changed in this file to make the whole thig work

    tks
    eudes

    Thursday, September 18, 2008 3:05 AM
  • What is the error that it throws?  It depends on what you need the app config to do.  There are a number of things you can add to the config file. 

     

    One thing you can do is see what is in the other app configs and compare them to mstest.exe.config and add the items into the mstest.exe.config file
    Thursday, September 18, 2008 1:55 PM
  • Hi,

    Bruce, I did what you mentioned in

    "One thing you can do is see what is in the other app configs and compare them to mstest.exe.config and add the items into the mstest.exe.config file"

    And it worked!

    Thank you very much for the precise hint!


    Thursday, September 18, 2008 6:40 PM
  • Hi guys,

    I have the same problem with the /noisolation flag. What I cannot comprehend is why MSTest cannot load the <testdll>.config file in the no isolation mode. The workaround of adding the config info to the MSTest.exe config file is not an acceptable solution. I hope this will be fixed.
    Tuesday, October 20, 2009 6:23 AM