开发者

Not able to debug unit tests in visual studio

开发者 https://www.devze.com 2023-03-09 22:48 出处:网络
I have the following xUnit unit test that is throwing nullReferenceException. So I decided to debug. However, when I deb开发者_如何学Goug my test fails before even it hits the first break point.

I have the following xUnit unit test that is throwing nullReferenceException.

So I decided to debug. However, when I deb开发者_如何学Goug my test fails before even it hits the first break point.

How do I fix this?

Not able to debug unit tests in visual studio


Before you run your unit tests the next time, hit CTRL-D, E to bring up the Debug | Exceptions window. To make it quicker, just put a check next to CLR Exceptions in the Thrown column. Now run. Hopefully, execution will break at the source of your NullReferenceException.


I had a similar issue in Visual Studio 2017. The unit test project was added automatically by the framework. I read many blogs, and nothing was able to solve my issue. Finally I got it to work using the following approach: At the Solution Level, Right Click => Properties=> Set them to Debug mode.


Seems like you've got an error that occurs before your test method. I'd check the constructor. It might be the test initialization code there.


Do you have methods with the xUnit-equivalents of MSTest's [ClassInitialize] or [TestInitialize] attributes? If one of those is throwing your NullReferenceException, that could be why it's not hitting your breakpoint.


I am not familiar with xUnit, but it sounds like your test class either:

  1. Fails in init method or constructor

  2. Can not be created from its DLL.

Make sure you ate copying any dependant DLLs and resources to test execution dir on static class int, prior to constructor of class bring called.

0

精彩评论

暂无评论...
验证码 换一张
取 消