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

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.

You can click "Cancel" in Test Explorer:
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

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

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.

For me the solution was to go to Task Manager, locate chromedriver and end the task.
Visual Studio 2022 Professional version 17.2.3.

I have found the solution to this issue. To stop the run after cancel is pressed, just set the 'Terminate process on cancel' option to True.

Related

Visual studio 2017 debug console saying "ops"

First off, i haven't been coding or using Visual studio for super long so please explain in details so i can follow. Thanks!
Every time i try to run any code i get the message "ops" in the debug window. I disabled my antivirus(windows defender) and reinstalled a bunch of times. I get the same issue using Visual studio 2019. Anyone have ideas ?
I tried a bunch of different codes and even the default hello world that the Windows Console Application gives you isn't running.
Please check for the existence of one of the following registry keys.
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
If they exist and are not expected, please remove. They may be created by malware, so you may need to use an antivirus product to remove the unwanted software.
Step 1: Add a breakpoint at the top of your program.
Step 2: Enlarge the tiny console window to a normal size.
Step 3: Click "Continue" on the debugger.
Step 4: "ops" turns into "To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops."

Only in unit test projects

Is this a new feature of VS 2017 that every time I am trying to debug a unit test, and point the cursor at a variable to inspect, VS freezes at first, then throw up this:
And if I hit F10 after this window finally goes away in 10-20 seconds, VS throws up this:
Is this a new normal and expected behavior, or I am missing any settings?
1) Please try to disable the option "Enable property Evaluation and other implicit function calls" under Tools->Options->Debugging->General.
2) Delete all of the breakpoints, reset the one that you want and debug again.
3) Another workaround could be to enable the option: "Use Managed Compatibility Mode" under Tools -> Options -> Debugging -> General, but it will disable Edit and Continue. Reference: Visual Studio 2015 update 3 crashing after "Getting DataTip text..."
4) Btw, the latest update of VS 2017 is 15.5.3, you may also try to update to it.
And of course, you could post the unit test code sample if it’s possible, since I could not reproduce this issue with unit test project in VS2017.

Get test list in MSTest via Command-Line [duplicate]

I just installed Visual Studio 2013 Premium and was having a good time playing with it and writing unit tests (using MS unit tests). However, the "Test Lists" window and some other Test related windows suddenly disappeared AND they have disappeared from the menu item
Test->Windows. In fact I remember Test->Windows having 4 items under it and now I only see two: Test Explorer, Code Coverage Results. i stress they WERE present in Visual Studio 2013. Clearly, I hit some key combination that made them disappear or something happened to make them disappear. How do I get Test List back? Please don't see they are under Tests->Windows, because for me, they are not (at least now. they were!)
Anyone else seen this? Any solutions? I tried restarting Visual Studio, rebooting.
Also, previously, under the "Test" menu, there was a Debug->"Test in Context" and a Run->"Test in Context", or something like this. It was very handy. If your cursor was with in some test, you could run just that one. I'm guessing this is related.
For all I know, these features have been "optimized" into the new test-window... a.k.a. they have been removed. Some other unit test related features are also gone (the context menu item for "create unit tests" is gone for example, yet can still be called via the command window)
Personally I think this is Microsoft's way of pushing everybody towards the Team Foundation Server but that's just my two cents.
I just had the same issue. In my case I needed to install the NUnit plugin ("Nunit test adapter"). After restarting the tests came back.
Start Developer Command Prompt:
cd to UnitTest-folder\bin\Debug which contains .dll
enter command: mstest /testcontainer:UnitTestMyTest.dll
(this creates the test-result)
in VS:
menu View / Other Windows / Test Results
manage Test Runs: window Test Runs -> connect to Test Run
browse to test-folder\bin\Debug\TestResults

Is it possible to run a unit test in debug mode?

I've fixed a null reference problem. Now when I run the test related to that class, it fails. I'd like to know whether is possible to run a test in debug mode so I'll know why I am getting the exception?
The test was written by some else, it's calling a method, as part of the setup, with a lot of logic in it. I'd like to step in to see how values are being returned.
Thank for helping.
It is indeed possible, using the NUnit Test Adapter for Visual Studio 2012.
Also, just so you're aware: failed assertions will throw exceptions, causing the debugger to break execution. You can adjust your configuration to work around this, as described in this thread:
Debugging in VS2012 with NUnit without throwing exceptions?
You can also use ReSharper, which makes it pretty easy. Or, you can just go into the properties for your DLL project that has the test in it and make the test runner you are using the exe that runs when you run the project.
Right click the project in the solution explorer, select "Properties" from the menu, go to the "Debug" tab, click the "Start external program" radio button then set the project as the active project and run in debug mode.

Debugging a solution and the test output is visible for less than a second

I'm having a problem with visual studio. I'm trying to run a unit test using the Google test framework and the output keeps flickering on for a sec and disappearing. How do I keep the output the executable shows on the screen so that I can see the results of the test?
It worked previously but I changed some of the settings (can't remember what) and now it just flickers on and off.
Run it with Debug > Start Without Debugging (Ctrl+F5) rather than Start Debugging (F5). When you do that, the IDE keeps the console open and waits for a key press after the program exits.