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?
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:
Fails in init method or constructor
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.
精彩评论