简体   繁体   English

WinDbg'ing单元测试C#

[英]WinDbg'ing Unit Tests C#

What's my question/problem? 我的问题是什么? I'm trying to use WinDBG to attach to a few of my unit tests, which are in a Class Library (Unit Test Project), but I can't get WinDbg to break on managed exceptions. 我试图使用WinDBG附加到我的一些单元测试中,这些单元测试位于类库(单元测试项目)中,但是我无法使WinDbg打破托管异常。

Why am I doing this? 我为什么要这样做? Currently I have tests that utilize shims and are bumping into this issue: UnitTestIsolationException: Throws Exception while running Shims test in Release/Debug mode 当前,我有利用垫片的测试,并且碰到了这个问题: UnitTestIsolationException:在Release / Debug模式下运行Shims测试时抛出异常

However, this is ONLY happening when these tests are run in tandem (same playlist in test explorer) with some other tests that aren't using shims. 但是,只有在这些测试与其他未使用垫片的测试同时运行(测试浏览器中的播放列表相同)时,才会发生这种情况。 When run individually, the tests pass fine. 单独运行时,测试可以通过。

So, I figured I'd fire up WinDbg (with my very limited knowledge of it), attach to the test runner, and break on the exceptions there. 因此,我以为我会启动WinDbg(以我非常有限的知识),将其附加到测试运行程序,并中断那里的异常。

What I've Tried: Since this is a DLL it's obviously being loaded up by some executable to run the code within the tests (test runner). 我尝试过的事情:由于这是一个DLL,很显然它是由某些可执行文件加载的,以便在测试(测试运行程序)中运行代码。 While I was originally just running these tests in Visual Studio, I had trouble determining which process to attach WinDbg too, so instead I started using vstest.console.exe to start running the tests, then attach to that. 虽然我本来只是运行在Visual Studio这些测试中,我遇到了麻烦,确定连接WinDbg过其中的过程,所以不是我开始使用vstest.console.exe开始运行测试,然后附加到这一点。

I'm able to attach fine, and WinDbg halts the execution of the test runner (yay!). 我可以执行附加操作,并且WinDbg暂停执行测试运行程序(是的!)。

Now, I want to break as soon as a CLR exception is thrown (meaning my UnitTestIsolationException). 现在,我想在引发CLR异常后立即中断(这意味着我的UnitTestIsolationException)。 After googling, I found the windbg command to do so: sxe clr 谷歌搜索后,我发现了windbg命令可以这样做: sxe clr

Then I type g , and the program starts running through my tests again. 然后,输入g ,该程序再次开始运行我的测试。

Behavior I'm seeing: WinDbg never breaks on the UnitTestIsolationException - all the tests run to completion, the test results are printed to the console, then the program terminates: 我看到的行为: WinDbg永不中断UnitTestIsolationException-所有测试运行完毕,测试结果打印到控制台,然后程序终止:

Passed   [SomePassingTestName]
Passed   [SomePassingTestName]
Failed   [TheFailedTestMethodName]
Error Message:
   Test method [TheFaileTestMethodName] threw exception:
   Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationExceptio
n: Unexpected error returned by SetDetourProvider in profiler library 'C:\Progra
m Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsof
t\IntelliTrace\14.0.0\Microsoft.IntelliTrace.Profiler.14.0.0.dll'.

我更喜欢psscor,但尝试

!StopOnException -derived -create System.Exception

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM