How to connect a debugger to the mstest command line

I have a unit test suite using mstest that I can run fine inside Visual Studio, but when my deployment scripts try to run tests using the command line call to mstest, it will be frozen during the test for half the time. This is probably a problem in the test, but, unable to reproduce the problem inside the debugger, I could not find the problem.

So far, I have not been able to attach the mstest process in order to be able to debug the problem, because when I attach and pause, I see nothing in the visual studio (none of them are specified, no known code). Is there anything strange about how he uses applications that prevent him from easily joining him? Any other useful ways to try and troubleshoot, is it even possible to make the Console WriteLine equivalent from within the test so that mstest displays it in the console window in which it works?

+6
source share
3 answers

Two options.

  • In the IDE, uncheck Test → Test Settings → Keep test.

or

  1. To use the command line:

Launch mstest using the / noisolation switch. It will run the tests directly, and not spawn an auxiliary process.

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

I am setting up the Debug tab for my test project as follows:

Run the external program: C: \ Program Files (x86) \ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ MSTest.exe

Command Line Arguments: / noisolation / testcontainer: MyProjectName.dll

+3
source

After viewing the process tree in Process Explorer, MSTest.exe starts a child process named QTAgent32_40.exe , I was able to connect to this process and disable only my code so that I could debug my tests.

It turns out that it was actually a dead end inside the simulated object I created that used MethodImplOptions.Synchronized

+2
source

Here is my suggestion for the vstest.console tool:

  • Add a new test method at the bottom of the test file, so this test will be performed first in vstest.console :

     [TestMethod] public void DebugAttachToProcessTimeout() { Console.ReadLine(); } 
  • Run Vstest.console.exe with the appropriate assembly as a parameter. The tool will try to check the first test and wait for user input.
  • Switch to Visual Studio and go to Debug → Attach to process (CTRL + ALT + P). Then select “Vstest.console.exe” and click “Attach”.
  • Now you can return to the console and press enter. The tool will continue to run tests with an attached visual studio.
0
source

Source: https://habr.com/ru/post/970636/


All Articles