How can I stop the Visual Studio Test Runner when a test hangs

35,189

Solution 1

You can click "Cancel" in Test Explorer:

enter image description here

Show Test Explorer by going to TEST > Windows > Test Explorer.

This is in Visual Studio 2013.

Instructions for other versions of VS can be found here

Solution 2

Sorry for waking up an old thread:) just wanted to share my solution here, I had the same issue on VS 2015. There is some text below the search input just where the cancel should appear (take a look at @Codeman print screen), the text is actually some description on how you can setup a build for your tests, the text is several lines and at the end you have "do not show this any more" just press it and then the cancel button appears:) Very strange bug, sorry I do not have some print screens of this hope it helps someone

Solution 3

VS2015. If the hanging tests are executables instead of DLLs you need to kill those tests in the task manager. You need to close the Test Explorer Window to prevent automatic running. While the tests are running/hanging you will not be able to compile the according project.

Share:
35,189

Related videos on Youtube

citykid
Author by

citykid

Versatile software craftsman. Focus on software engineering and human computer interaction (design). Vanilla code writer. preferred tools dotnet core runtime on all platforms, typescript or c++ or rust.

Updated on May 21, 2020

Comments

  • citykid
    citykid almost 4 years

    When a test hangs in a loop, the small green progress bar in the test runner does not proceed, but there is no way to stop the test run. Or is there?

    VS 2013

    Edit: This occured when using the XUnit TestRunner. The Cancel button simply did not show up. After testing various test runners in a new solution, it turned out, that it works with all of them. Finally it also worked with my original solution. So there was some anomaly in the state of my VS environment that caused cancel to disapper.

    • Billy ONeal
      Billy ONeal over 10 years
      You can kill the test runner process :)
    • citykid
      citykid over 10 years
      Yepp, I just thought there would be something smoother, because hanging tests are not soooo rare.
  • citykid
    citykid over 10 years
    Very interesting: I do not have this cancel button! I have there: "Run All" | "Run ..." | "Playlist"
  • Codeman
    Codeman over 10 years
    It's only available while running a test. And like I said, this is VS2013.
  • Codeman
    Codeman over 10 years
    I added a link to instructions for other versions.
  • citykid
    citykid over 10 years
    Hmm, never shows up on my machine. Strange. Anyway, this is certainly the answer. I will keep an eye on that. Thx
  • Codeman
    Codeman over 10 years
    Thanks! Please make sure to mark an answer as correct if it answered your question. And check out the link I added!
  • citykid
    citykid over 10 years
    I guess it is related that I use the XUnit Runner. Might be a bug there.
  • Codeman
    Codeman over 10 years
    Ah, the one I am talking about is MSTest. That might make a difference. Perhaps tag your question differently? I assumed you were using the default unit testing stuff in VS.
  • citykid
    citykid over 10 years
    Just came to my mind now, that I currently use XUnit in F#. Tagged XUnit. Thx for your input.
  • citykid
    citykid about 7 years
    waking up an old thread is totally fine. stackoverflow even has a bagde to honor this ;-)
  • AardVark71
    AardVark71 over 4 years
    Tx. Had this in VS2017. Could not cancel and had to kill the testhost.exe process
  • Sungwon Jeong
    Sungwon Jeong almost 4 years
    Thank you. I had no idea why my VS2017 hangs. Simply close the Test Window solved my issue.