Search code examples
c#debuggingmstestvisual-studio-debugging

How to attach debugger to command line mstest


I have a unit test suite using mstest that I can run fine frome inside visual studio, but when my deploy scripts tries to run the tests using a command line call to mstest it will freeze during a test half the time. It is likely a problem in the test, but without being able to reproduce the issue inside a debugger I have been unable to find the issue.

So far I have been unable to attach the mstest process to be able to debug the issue, as when I attach and pause I see nothing in visual studio (no threads listed, no known code). Is there something odd about how it uses appdomains that prevents easily attaching to it? Any other good ways to try and troubleshoot, is it even possible to do the equivalent of Console WriteLine from inside the test so that mstest will display it in the console window its running in?


Solution

  • Two options.

    1. In the IDE uncheck Test -> Test Settings -> Keep Test execution engine running.

    or

    1. To use the commandline:

    Run mstest with the /noisolation switch. It will execute the tests directly rather than spawning a helper process.

    Mixed: Automatically attach the VS debugger to the command line mstest.exe:

    I configure the Debug tab for my test project with the following:

    Start External Program: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe

    Command line arguments: /noisolation /testcontainer:MyProjectName.dll