Visual Studio - suddenly cannot debug tests
T

33

76

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?

Toothlike answered 2/8, 2013 at 18:43 Comment(3)
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 :/Toothlike
Possible duplicate of Visual Studio "Debug Unit Test" fails to hit breakpointsStannite
Related post - Visual Studio 15.8.1 not running MS unit testsPlatter
T
65

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.

Townsend answered 24/10, 2017 at 5:44 Comment(2)
If I could, I would hug your right now. This has been annoying me for hours lol.Methodist
I fill so dumb, suddenly...Redcap
D
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.

Davie answered 3/10, 2013 at 15:42 Comment(2)
applied the settings you mentioned but not working yetScauper
Alternatively make sure you don't have VS set to Release mode. I just made this mistake. You have to be on Debug in order to debug tests.Barrus
L
26

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)

Legume answered 24/9, 2020 at 22:22 Comment(2)
Thank - You - KING!Bireme
B I N G O ! ! ! !Weis
S
18

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.

Suspensor answered 9/7, 2014 at 22:49 Comment(2)
even " IT crowd" folks can fix this! It worked for meOsmanli
Working for me in VS 2017. What precipitates the issue for me is stopping debugging; I have to let the debug session run to completion or it breaks the Debug Tests command.Weathered
D
15

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();
}
Disinfect answered 26/5, 2018 at 23:18 Comment(1)
This was my case on VS2019 and it worked perfectly.Marionmarionette
M
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

Monkfish answered 1/11, 2018 at 20:15 Comment(2)
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: msdn.microsoft.com/en-us/library/…Monkfish
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!Halonna
B
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.

Bedding answered 30/8, 2017 at 10:11 Comment(3)
close all of my visual studio and clear temp and remove bin and obj folder works for me,thanksSanjay
I wasn't sure about step2 so I skipped it and proceeded with Step3 then 4 and problem resolved. thank you @Om Sao ...Afb
and @swathi cv !!Afb
C
5

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

Carillon answered 24/8, 2017 at 8:45 Comment(1)
THANK YOU! This worked for me after fussing over this for hours.Tuberculin
G
5

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
Gujral answered 29/5, 2018 at 10:39 Comment(1)
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.Aged
P
3

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.

Password answered 17/10, 2018 at 19:31 Comment(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.Corlisscorly
S
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

Stannite answered 1/2, 2019 at 19:52 Comment(0)
E
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.

Elise answered 21/4, 2016 at 7:35 Comment(0)
A
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

Amato answered 14/8, 2013 at 12:53 Comment(1)
What's confusing is that in the link they call it "VS2013 Update 3".Secular
W
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.

Workhouse answered 18/8, 2016 at 14:43 Comment(1)
Did you actually use Ctrl+R, Ctrl+T (which is Debug, not Run)? for Run it’s expected not stop on breakpoint.Braden
C
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

Controvert answered 12/1, 2018 at 1:50 Comment(0)
N
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!

Needful answered 8/11, 2018 at 11:40 Comment(0)
S
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.

Streamlined answered 5/3, 2019 at 13:13 Comment(2)
thanks a lot! I change all my projects to Any CPU and worked!Rectangular
@HernaldoGonzalez glad to hear that!. Happy hacking my friend :))Streamlined
M
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

Mcclenaghan answered 24/6, 2020 at 15:19 Comment(0)
L
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

Lashonda answered 29/12, 2020 at 0:21 Comment(0)
H
1

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

Heptarchy answered 13/7, 2021 at 21:2 Comment(0)
D
1

I had the same problem in Visual Studio 2019.

For me worked using Repair command of Visual Studio Installer.

enter image description here

Derisible answered 7/11, 2021 at 9:55 Comment(0)
Y
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.

Youlandayoulton answered 17/5, 2016 at 17:12 Comment(0)
T
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".

Testaceous answered 28/2, 2018 at 21:34 Comment(0)
N
0

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

enter image description here

Nydia answered 28/6, 2018 at 13:14 Comment(0)
S
0

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

Syndesis answered 29/7, 2018 at 14:49 Comment(0)
P
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.

Parvenu answered 8/10, 2018 at 13:45 Comment(0)
L
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?

Lustig answered 21/10, 2018 at 7:10 Comment(0)
B
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
Buckjump answered 12/11, 2018 at 9:24 Comment(0)
A
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.

Analogous answered 9/3, 2020 at 14:12 Comment(0)
C
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.

Crosswalk answered 14/5, 2020 at 12:20 Comment(0)
B
0

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

Barriebarrientos answered 10/12, 2020 at 17:25 Comment(0)
F
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.

Fen answered 14/12, 2021 at 1:6 Comment(0)
E
-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.

Euripus answered 31/3, 2014 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.