Visual Studio - suddenly cannot debug tests

2020-02-18 03:32发布

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?

24条回答
我只想做你的唯一
2楼-- · 2020-02-18 03:50

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.

查看更多
淡お忘
3楼-- · 2020-02-18 03:51

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.

查看更多
做自己的国王
4楼-- · 2020-02-18 03:51

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.

查看更多
戒情不戒烟
5楼-- · 2020-02-18 03:52

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
查看更多
萌系小妹纸
6楼-- · 2020-02-18 03:52

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.

查看更多
做个烂人
7楼-- · 2020-02-18 03:53

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

查看更多
登录 后发表回答