socialMatrix
socialMatrix

Reputation: 1443

Not able to debug unit tests in visual studio

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?

enter image description here

Upvotes: 3

Views: 11234

Answers (5)

Bernie Shishaye
Bernie Shishaye

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

Danny Varod
Danny Varod

Reputation: 18069

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.

Upvotes: 0

Assaf Stone
Assaf Stone

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

Daniel Mann
Daniel Mann

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

Dave
Dave

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

Related Questions