11

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?

2
  • 1
    Make sure you select correct debugger type when attaching - try to specify explicitly instead of autodetect. Commented Jun 10, 2014 at 16:29
  • Hmm, odd. You can do Trace.WriteLine, and it will appear in the generated .trx, but I'm not sure it writes the report until the very end... Commented Jun 10, 2014 at 16:30

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

Comments

4

After looking at the process tree in Process Explorer, MSTest.exe was launching a child process named QTAgent32_40.exe, I was able to attach to that process and turn off Just my code so that I could debug my tests.

Turns out it was effectively deadlocking inside a mock object I created that was using MethodImplOptions.Synchronized

1 Comment

Even though you figured it out, I would recommend that Rob's answer below be anointed the "answer", because he addresses how to debug from inside VS, as well as how to overcome the subprocess launching. I had a similar problem to you, and his answer provided the key(s).
1

Here is my suggestion for vstest.console tool:

  1. Add new test method at the top of test file, so this test will be executed first in vstest.console tool:

    [TestMethod]
    public void DebugAttachToProcessTimeout()
    {
        Console.ReadLine();
    }
    
  2. Start Vstest.console.exe with appropriate assembly as param. Tool will try to check first test and wait for user's input.

  3. Switch to Visual Studio and go to Debug -> Attach to process (CTRL+ALT+P). Then select 'Vstest.console.exe' and click 'Attach'.

  4. Now you can go back to console and press enter. Tool will continue execute tests with attached visual studio.

1 Comment

this worked well - but I had to put the new test method at the top of the file (instead of bottom) to get it to pause before executing the other tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.