Reputation: 1443
I have the following xUnit unit test that is throwing nullReferenceException.
So I decided to debug. However, when I debug my test fails before even it hits the first break point.
How do I fix this?
Upvotes: 3
Views: 11234
Reputation: 51
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.
Upvotes: 4
Reputation: 18069
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.
Upvotes: 0
Reputation: 6317
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.
Upvotes: 1
Reputation: 58980
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.
Upvotes: 0
Reputation: 15016
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
.
Upvotes: 4