Visual Studio - suddenly cannot debug tests

Visual StudioVisual Studio-2012Visual Studio-2017Visual Studio-DebuggingVs Unit-Testing-Framework

Visual Studio Problem Overview


I'm not sure what I did, but all of a sudden, my Visual Studio 2012 will not debug any tests.

If I select a test from the Test Explorer and tell it to run, it simply outputs this in the Test Output window:

> ------ Discover test started ------
> ========== Discover test finished: 29 found (0:00:01.3371755) ==========
> ------ Run test started ------ Process with an Id of -1 is not running.
> ========== Run test finished: 0 run (0:00:01.4711861) ==========

what the heck does that mean?! After doing this a few times, the error changed to:

The Operation was Cancelled

which I sure didn't do.

It's doing this on every test in the list.

however, I can RUN the tests no problem, and they pass... but I cannot debug the tests.

What might I have done? I did not actively go into any settings and change anything, perhaps a stray click somewhere, but where?

Visual Studio Solutions


Solution 1 - Visual Studio

I encountered this today. I tried closing the solution but it didn't work. My mistake I set my solution to Release Mode instead of Debug Mode. I set it to Debug then it worked as expected.

I'm using VS 2015 professional.

Solution 2 - Visual Studio

I was getting the same output after upgrading a test project from VS 2010 to VS 2012 Ultimate Update 3. The message was displayed in Test Output window after using MSTest command to Debug Selected Tests.

I tried to debug tests using Resharper 8 Unit Test Session window. The message in the result window was "Test wasn't run".

The solution that helped me was to modify the test project settings to enable native code debugging as instructed at this link: Uncaught exception thrown by method called through reflection

In case the link does not work:

  1. Go to the project right click and select properties.
  2. Select 'Debug' tab on the left.
  3. Go to ‘Enable Debuggers’ on the bottom
  4. Check ‘Enable Native code debugging’ (or 'Enable unmanaged code debugging', depends on version) check box

Thanks to GalDude33 for posting the solution.

Solution 3 - Visual Studio

Have regularly the same issue with Visual Studio 2012.

Solution : close the current solution and reopen it.

In my case closing and reopening VS was not necessary.

Solution 4 - Visual Studio

Async Tests - Symptoms in my scenario were similar in that my test was not executing and my breakpoint was not getting hit. The Test Explorer in Visual Studio could see the test, but I could not debug it. Running it acted as though it could not be found even though it could be seen in the Test Explorer.

In case it helps someone else, my issue was as simple as having to change the test method's signature from "async void" to "async Task".

Do this:

[TestMethod]
public async Task CorrectlyFailingTest()
{
  await SystemUnderTest.FailAsync();
}

Not this:

[TestMethod]
public async void CorrectlyFailingTest()
{
  await SystemUnderTest.FailAsync();
}

Solution 5 - Visual Studio

In my case, it was the launchSettings.json file which was causing the debugger not to be able to hit a breakpoint. Not sure why the file was present in a unit test type of project (probably some unwanted leftover), however, xunit seemed not to ignore it. I simply deleted the file and I was able to debug the unit tests again.

Env: Microsoft Visual Studio Enterprise 2019 Preview (Version 16.8.0 Preview 3.1)

Solution 6 - Visual Studio

I was unable to attach to my debugger because it was looking for test settings file.
If this is your issue then go to Test->Test Settings->Uncheck Local.testsettings option

Unit Test Debugging Fix

Solution 7 - Visual Studio

Please follow below steps. It worked for me

Steps.

1.Close your visual studio instances

2.Clean you temp files and prefetch files.

3.delete the files in project bin folder.

4.Restart the applications.

Solution 8 - Visual Studio

For me, updating MSTest.TestAdapter and MSTest.TestFramework Nuget packages to latest version resolved the problem.

Solution 9 - Visual Studio

Ensure your test project is part of the projects to build.

  • Right click your solution from Solution Explorer
  • Go to Set StartUp Projects..
  • Click on Configuration Properties and ensure your test project is checked for build

Solution 10 - Visual Studio

I was having similar issue in VS2015. Only one unit test could not be debugged in my case. Debugger would initialize a test, but would not debug test itself, nicely exiting. The problem was in Resharper importing Newtonsoft.Json library without enabling NuGet package for the project. (I used Alt+Enter to automatically import the library)

Solution was to install Newtonsoft.Json NuGet package for test project.

Solution 11 - Visual Studio

As of Visual Studio 2017 (15.8), this can happen when the Live Unit Testing feature is active. There's no clear message in the output; it just starts and stops without debugging. The solution is stopping the live testing so then you can debug the test normally.

Solution 12 - Visual Studio

In my case, my symbols weren't loaded.

I had to go to Tools -> Options -> Debugging -> Symbols and select "Load all modules, unless excluded" for breakpoints to get hit.

enter image description here

Solution 13 - Visual Studio

Take a look at the following link there is an update that fixing it. Visual studio 2012 update 3.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/e96f53c7-dc8c-4274-8756-eb745de701e8/visual-studio-2012-update-3-cant-debug-unit-test

Solution 14 - Visual Studio

When I use Visual Studio 2012, for some reasons, if I use shortcut ctrl R+T, it will hit the break point. But if I click "Run All" or "Run Selected Test" on Test Explorer, it won't. Visual Studio 2013 works fine both ways though.

Solution 15 - Visual Studio

Hitting "Run tests" will not trigger the brakepoints.

To debug your code and stop at a breakpoint in a test:

Right-click > Debug Tests

or

"Test" tab > Debug > All tests

Solution 16 - Visual Studio

This might not be a solution to your problem specifically, but I also couldn't debug a test that I had written. Turns out the solution was quite simple:

Change the method from private to public. I don't know why debugging isn't possible within private methods, but it's probably got something to to with the [Test] attribute's implementation. Hope this helps anyone struggling with a similar problem in the future!

Solution 17 - Visual Studio

None of the proposed solutions worked for me. What worked for me is changing the unit test project and all dependent projects' platform target to Any CPU instead of x64 which is some kind of a workaround not a real fix !!

EDIT

The target platform for a unit test project could be changed from test settings not from the project's properties. Refer to this answer for more.

Solution 18 - Visual Studio

Just like you guys, I wasn't able to Debug nor Run Unit Tests of my MSBuild Tests Project in Visual Studio 2019 16.6.2. The code I wanted to Unit Test is in a Class Library based on .Net 4.6.2. The Test Explorer always stated "Tests Not Run" with the blue information icon beneath.

So I just tried to create a new Unit Test from within the Code File of the Method I wanted to test => and it worked! Exact steps I went through: In the C# File go to the method, right click on it and select "Create Unit Tests" and let the dialog create a new project. After adding the Test Code from my original files all went fine and I am able to Debug and Run my Test Methods!

Hope this simple solutions helps some of you, too. Best regards

Solution 19 - Visual Studio

With me I simply added xunit.runner.visualstudio (latest stable version at the time was 2.4.2) and that did the trick.

Solution 20 - Visual Studio

For me the problem was that my config file (app.config) didn't have the Debug Transformation file (app.Debug.config), once I added it start working/debugging again.

Solution 21 - Visual Studio

For me the problem was that after upgrading to 2017 v15.5.7 my solution's properties got changed somehow. Which made it where I could run the test once in debug mode, but not again, unless I restarted VS, then it would work again, once. Once I set it back it worked again. The setting was, and should be, for me, Solution > Common Properties > Startup Project > Multiple startup projects. Somehow it got set to "Single startup project".

Solution 22 - Visual Studio

Check that the test project and the main project are using the same framework version.

enter image description here

Solution 23 - Visual Studio

Solution: Select 'Debug Unit Tests' or 'Run Unit Tests' instead of 'Debug Tests' or 'Run Tests'.

Solution 24 - Visual Studio

app.config problem references can unwittingly cause the debugger not to attach and breakpoints not to be hit when debugging test projects. This file may have been updated by packages or has gone out of date.

Solution: I generally copy then remove all dependencies under the runtime tag from the test project's app.config. Debugging usuually starts working after this but some references may need to be added back if assemblies can't be found.

Solution 25 - Visual Studio

In my case, the break point can't be hit if there is build warning(s). I can verify this by toggle the line of code with warning. It was a unused string with length 66000. (Warning CS0219 The variable 'XXXXXXX' is assigned but its value is never used)

I guess the compiler removed this line so the symbol mapping failed?

Solution 26 - Visual Studio

For me the following worked:

  1. Close Solution
  2. Close Visual Studio
  3. Delete the contents of "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"
  4. Delete the contents of "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files"
  5. Open Visual Studio
  6. Open Solution

Solution 27 - Visual Studio

I just faced a similar issue, where NUnits TimeoutAttribute caused the test to be cancelled when debugging without a meaningful message.

Removing the attribute from the test fixed the issue.

Solution 28 - Visual Studio

If you created a project in an older Visual Studio and are now using VS 2019, you must install the Microsoft.VisualStudio.TestPlatform library and update others.

Solution 29 - Visual Studio

In my case, it was because I was using a non-static method as the dynamic data source for a Data test method.

Solution 30 - Visual Studio

For me I went to Test explore -> setting -> processor Architecture For AnyCPUProjects and changed it to X64 and it worked for me.

enter image description here

Solution 31 - Visual Studio

I had the same problem in Visual Studio 2019.

For me worked using Repair command of Visual Studio Installer.

enter image description here

Solution 32 - Visual Studio

In my case it was the test project having a reference Microsoft.NET.Sdk.Function:

    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />

Once it was removed the debugger stops at the breakpoints set.

Solution 33 - Visual Studio

Saw this post while investigating the same issue; This solved it for me (posting this in case others encounter the same):

System: Windows 7, 64 bit on Intel i5

Actions:

  • Downloaded VS2012 Update pack 4 from Microsoft
  • Set the UAC (press Windows key, enter UAC) to Default
  • Uninstall Update pack 4
  • (Mandatory) restart
  • Set the UAC to Default again (somehow it got reset to none)
  • Install Update pack 4

The UAC thing was something that was mentioned somewhere else, but I don't know if this was a necessary step.

Recommended Vs Unit-Testing-Framework Solutions

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSelAromDotNetView Question on Stackoverflow
Solution 1 - Visual StudioTom MabaquiaoView Answer on Stackoverflow
Solution 2 - Visual StudioBrankoView Answer on Stackoverflow
Solution 3 - Visual StudioPragmateekView Answer on Stackoverflow
Solution 4 - Visual StudioPaul SchroederView Answer on Stackoverflow
Solution 5 - Visual StudiorockyView Answer on Stackoverflow
Solution 6 - Visual StudioMatthew PetersonView Answer on Stackoverflow
Solution 7 - Visual Studioswathi cvView Answer on Stackoverflow
Solution 8 - Visual StudioYoungjaeView Answer on Stackoverflow
Solution 9 - Visual StudioPeter OmbwaView Answer on Stackoverflow
Solution 10 - Visual Studiouser2957464View Answer on Stackoverflow
Solution 11 - Visual StudioArturo Torres SánchezView Answer on Stackoverflow
Solution 12 - Visual StudiopushkinView Answer on Stackoverflow
Solution 13 - Visual Studiouser2682517View Answer on Stackoverflow
Solution 14 - Visual StudiopaibambooView Answer on Stackoverflow
Solution 15 - Visual StudioChris MathewView Answer on Stackoverflow
Solution 16 - Visual StudioAndreas ForslöwView Answer on Stackoverflow
Solution 17 - Visual StudioIbrahim AmerView Answer on Stackoverflow
Solution 18 - Visual StudioCordtView Answer on Stackoverflow
Solution 19 - Visual StudioHarold_FinchView Answer on Stackoverflow
Solution 20 - Visual StudioJaiderView Answer on Stackoverflow
Solution 21 - Visual StudioShawn SmithView Answer on Stackoverflow
Solution 22 - Visual StudioMarco StaffoliView Answer on Stackoverflow
Solution 23 - Visual StudioRavi Kant ShivhareView Answer on Stackoverflow
Solution 24 - Visual StudiomhappsView Answer on Stackoverflow
Solution 25 - Visual StudioYipingView Answer on Stackoverflow
Solution 26 - Visual Studiowh1tet1pView Answer on Stackoverflow
Solution 27 - Visual StudionozzlemanView Answer on Stackoverflow
Solution 28 - Visual StudioH2OcView Answer on Stackoverflow
Solution 29 - Visual StudioEricView Answer on Stackoverflow
Solution 30 - Visual StudioGaurav JoshiView Answer on Stackoverflow
Solution 31 - Visual StudiogsscoderView Answer on Stackoverflow
Solution 32 - Visual StudiotymtamView Answer on Stackoverflow
Solution 33 - Visual StudioAutomatedChaosView Answer on Stackoverflow