72

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?

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
SelAromDotNet
  • 4,715
  • 5
  • 37
  • 59
  • running as admin didn't work, rebooting didn't work... but somehow rebooting and running as admin did work... I changed nothing else! sigh... well it's working if it keeps up will post this as answer :/ – SelAromDotNet Aug 02 '13 at 19:20
  • Possible duplicate of [Visual Studio "Debug Unit Test" fails to hit breakpoints](https://stackoverflow.com/questions/4332112/visual-studio-debug-unit-test-fails-to-hit-breakpoints) – pushkin Feb 01 '19 at 19:38
  • Related post - [Visual Studio 15.8.1 not running MS unit tests](https://stackoverflow.com/q/51967866/465053) – RBT Apr 27 '21 at 07:31

33 Answers33

64

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.

Tom Mabaquiao
  • 779
  • 7
  • 10
27

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.

Community
  • 1
  • 1
Branko
  • 279
  • 3
  • 4
24

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)

rocky
  • 7,506
  • 3
  • 33
  • 48
17

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.

Pragmateek
  • 13,174
  • 9
  • 74
  • 108
14

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();
}
Paul Schroeder
  • 1,460
  • 1
  • 14
  • 21
7

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

Matthew Peterson
  • 1,055
  • 12
  • 21
  • What's the reasoning behind the down vote? If you're referencing test settings that don't exist then it will cause issues with debugging unit tests. More info here: https://msdn.microsoft.com/en-us/library/ee256991.aspx?f=255&MSPPError=-2147217396 – Matthew Peterson Nov 02 '18 at 14:28
  • There seem to be loads of problems and associated solutions for this symptom, but this one was the one to help me. Disabling runsettings file in VS2017 works. Thanks! – Eike Mar 02 '20 at 09:59
6

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.

Om Sao
  • 7,064
  • 2
  • 47
  • 61
swathi cv
  • 61
  • 1
  • 2
5

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

Youngjae
  • 24,352
  • 18
  • 113
  • 198
4

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
Peter Ombwa
  • 211
  • 1
  • 3
  • If you are using a deployment tool - and not doing Tests for CI/CD - you may have to uncheck the Unit Test project - for your CI/CD and when you add new tests - you have to recheck it for your Unit testing again - which would be nice to have a warning on adding a new test - but you have to manually check if it is checked on your Debug build. – Mark W. Mitchell Nov 01 '18 at 15:34
3

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

Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75
pushkin
  • 9,575
  • 15
  • 51
  • 95
2

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.

2

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.

Arturo Torres Sánchez
  • 2,751
  • 4
  • 20
  • 33
  • 1
    I even have to rebuild the project after deactivating live testing. After that each test is showing a blue exclamation mark, and debugging is working once again. – Kai Hartmann Sep 10 '19 at 13:51
1

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

1

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.

paibamboo
  • 2,804
  • 17
  • 16
1

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

1

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!

Andreas Forslöw
  • 2,220
  • 23
  • 32
1

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.

Ibrahim Amer
  • 1,147
  • 4
  • 19
  • 46
1

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

Cordt
  • 49
  • 5
1

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

Gaurav Joshi
  • 861
  • 1
  • 11
  • 17
1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Harold_Finch
  • 682
  • 2
  • 12
  • 33
1

I had the same problem in Visual Studio 2019.

For me worked using Repair command of Visual Studio Installer.

enter image description here

gsscoder
  • 3,088
  • 4
  • 33
  • 49
0

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.

Jaider
  • 14,268
  • 5
  • 75
  • 82
0

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".

0

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

enter image description here

Marco Staffoli
  • 2,475
  • 2
  • 27
  • 29
0

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

0

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.

mhapps
  • 1,023
  • 8
  • 15
0

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?

Yiping
  • 971
  • 10
  • 31
0

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
wh1tet1p
  • 61
  • 1
  • 3
0

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.

nozzleman
  • 9,529
  • 4
  • 37
  • 58
0

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.

H2Oc
  • 1
0

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

Eric
  • 1,392
  • 17
  • 37
0

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.

tymtam
  • 31,798
  • 8
  • 86
  • 126
-1

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.

AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47