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条回答
ら.Afraid
2楼-- · 2020-02-18 03:36

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.

查看更多
Lonely孤独者°
3楼-- · 2020-02-18 03:42

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
查看更多
ら.Afraid
4楼-- · 2020-02-18 03:43

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.

查看更多
我想做一个坏孩纸
5楼-- · 2020-02-18 03:43

In my case, my symbols weren't loaded.

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

enter image description here

查看更多
贼婆χ
6楼-- · 2020-02-18 03:43

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.

查看更多
smile是对你的礼貌
7楼-- · 2020-02-18 03:44

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.

查看更多
登录 后发表回答