locked
How to generate MSTest log file? RRS feed

  • Question

  • Hi,

    I have several Native, x64 unit tests in Visual Studio 2013 Premium Update 3. I'm trying to debug a particular unit test that is only failing in Release mode and was hoping to get output from the unit test since the output window in Visual Studio is only saying "The active Test Run was aborted because the execution process exited unexpectedly. Check the execution process logs for more information. If the logs are not enabled, then enable the logs and try again."

    After searching online to try and figure out how to enable the logs, I came across this post: https://social.msdn.microsoft.com/Forums/en-US/8c7cc7dd-05d8-4ab3-a852-cefe708b68bf/have-mstest-output-my-log-file-at-a-desired-location?forum=vsunittest

    I modified the MSTest.exe.config as described.  Here is my file:

    <?xml version ="1.0"?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
      </startup>
      <runtime>
        <DisableFXClosureWalk enabled="true" />
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="PrivateAssemblies;PublicAssemblies;PrivateAssemblies\DataCollectors;PrivateAssemblies\DataCollectors\x86"/>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.UnitTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="10.1.0.0-11.1.0.0" newVersion="10.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.WebTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="8.0.0.0-11.0.0.0" newVersion="10.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.LoadTestFramework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
            <bindingRedirect oldVersion="8.0.0.0-11.0.0.0" newVersion="10.0.0.0"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <system.diagnostics>
        <trace autoflush="true" indentsize="4">
          <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\temp\MSTest.log" />
          </listeners>
        </trace>
        <switches>
          <add name="EqtTraceLevel" value="4" />
        </switches>
      </system.diagnostics>
      <appSettings>
        <add key="GetCollectorDataTimeout" value="300"/>
        <add key="TestProjectRetargetTo35Allowed" value="true" />
      </appSettings>
    </configuration>

    However, no log file is produced for any unit test, passing or failing, run under debug or release.  Did I make a mistake in the config file?  Is there another location where the logs are produced?  Is there another way to activate the MSTest logs?  Any help is greatly appreciated.

    Thank you.

    Tuesday, May 10, 2016 9:40 PM

Answers

  • Hi Karim Nogasm,

    The behavior in VS2013 is same to VS2015. I also tested it in VS2013 Update5. And I am able to get the log file as well.

    I can't get mstest log file when running through Test Explorer. I can only get it through MSTEST command line.

    Please upgrade your VS2013 to VS2013 Update5 then try it again.

    Best Regards,

    Lake Xiao

    Monday, May 16, 2016 1:11 AM

All replies

  • Hi Karim Nogas,

    Thanks for your post.

    >>However, no log file is produced for any unit test, passing or failing, run under debug or release. 

    As far as I know, if you run your test in Visual Studio. It will not generate the .trx result file by default.

    There is no need to modify the MSTest.exe.config file. If you want to generate the MSTEST result file. One idea is that you could use MSTEST command line to run your unit test. Then it will generate a .trx file in the "Debug\TestResults" folder.

    By the way, you could specify the .trx output directory using /resultsfile.

    This command line for your reference:

    mstest /testcontainer:"C:\Users\Administrator\Source\Repos\222\UnitTestProject7\UnitTestProject7\bin\Debug\UnitTestProject7.dll"

    Reference about MSTest.exe command-line options:

    https://msdn.microsoft.com/en-us/library/ms182489(v=vs.140).aspx

    Best Regards,

    Lake Xiao




    • Proposed as answer by lake Xiao Wednesday, May 11, 2016 3:15 AM
    • Edited by lake Xiao Wednesday, May 11, 2016 3:21 AM
    Wednesday, May 11, 2016 3:14 AM
  • Hi,

    Sorry, I included the wrong link in my original post.  I know other people have been successful at generating the log files from MSTest as referenced in this blog post: https://blogs.msdn.microsoft.com/aseemb/2013/01/25/how-to-enable-mstest-logs/

    I'm not interested in the .trx file, I'm interested in a .log file from MSTest to debug why the unit test is crashing.  As I mentioned above, Visual Studio is asking me to enable the logs:

    "The active Test Run was aborted because the execution process exited unexpectedly. Check the execution process logs for more information. If the logs are not enabled, then enable the logs and try again."

    Thanks.

    Wednesday, May 11, 2016 3:38 PM
  • Hi Karim Nogas,

    I just test it in my side. After add that snippet into the mstest.config file. When I ran my test using MSTest Command line, I can generate the MSTest Log file in the specified folder successfully.

    Please make sure the "temp" folder is exist in your C disk. Then create a new simple unit test project, run the unit test using MSTest command line, try it again.

    Best Regards,

    Lake Xiao

    Thursday, May 12, 2016 1:03 AM
  • Thanks for the reply. 

    Does this work when running the unit test through Test Explorer in Visual Studio? 

    I'm having difficulty executing the test on the command line because we're working in a 64-bit environment. I get the following messge: 

    "If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///XXX' or one of its dependencies. The module was expected to contain an assembly manifest."

    I don't have a .testsettings file as we're running everything through Visual Studio. All we have to do to run it in a 64-bit environment is to set Test > Test Settings > Default Processor Architecture > x64.

    If the log file will not be generated when running through the Test Explorer, how do I specify that my tests are 64-bit?  I see a /platform option but when I set that I get more complaints about not seeing the server.  I'm not interested in publishing the results anywhere; I just want to locally run one crashing, 64-bit test, and generate a log file to debug.

    Thanks.

    Thursday, May 12, 2016 8:49 PM
  • Hi Karim Nogas,

    >>Does this work when running the unit test through Test Explorer in Visual Studio?

    No, you need to run your test using MsTest Command line.

    By the way, my system environment is also the 64-bit.

    When did you get this error message?  Please restart your machine then follow the steps below:

    1.Run your Visual Studio as administrator and open your unit test project.

    2.Open the Develop Command Prompt for VS2015.

    3.Enter the mstest command line like this :

    mstest /testcontainer:"C:\Users\Administrator\Source\Repos\222\UnitTestProject7\UnitTestProject7\bin\Debug\UnitTestProject7.dll"

    Best Regards,

    Lake Xiao

    Friday, May 13, 2016 1:27 AM
  • Hi,

    I am on Visual Studio 2013, not 2015.

    I get that message when I execute the command just like you have written.  This occurs for all of our .dll test containers.

    Incidentally, I did "magically" get a MSTest.log although I've only run unit tests through the Test Explorer window.  Of course, I don't know when or how it happened because I can't reproduce it on demand.

    Saturday, May 14, 2016 8:49 PM
  • Hi Karim Nogasm,

    The behavior in VS2013 is same to VS2015. I also tested it in VS2013 Update5. And I am able to get the log file as well.

    I can't get mstest log file when running through Test Explorer. I can only get it through MSTEST command line.

    Please upgrade your VS2013 to VS2013 Update5 then try it again.

    Best Regards,

    Lake Xiao

    Monday, May 16, 2016 1:11 AM
  • Hi Lake,

    It will be a while before we get IT approval to have our systems are updated to VS2013 Update 5 so I will be unable to verify that that will fix this problem.  You can mark it as an answer and I will revisit this at a later date.

    Thanks.

    Tuesday, May 17, 2016 9:14 PM
  • Hi Lake,

    It will be a while before we get IT approval to have our systems are updated to VS2013 Update 5 so I will be unable to verify that that will fix this problem.  You can mark it as an answer and I will revisit this at a later date.

    Thanks.

    Hi Karim Nogas,

    If so, I will mark Lake's reply as the answer, of course, if it is not helpful, you could unmark it and post your latest information about this issue, we will follow up this issue in time.

    Have a nice day,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 19, 2016 1:46 AM