ExpectedExceptionBaseAttribute and “Object reference not set to an instance of an object”

You’re writing unit tests with Visual Studio and you want to verify that you’re throwing the correct Exception. You could use ExpectedExceptionAttribute class but it only allows you to verify the type of the Exception. You might want to verify other properties so you decide to create a subclass of¬†ExpectedExceptionBaseAttribute, which allows you to have your own Exception verification logic.

Unfortunately, if you’re using Visual Studio 2012 RTM (or with Update 1 or Update 2). You will run into a weird error at run time:¬†“Object reference not set to an instance of an object”.

What’s the solution? Install Visual Studio Update 3.

You can get more details from here: https://connect.microsoft.com/VisualStudio/feedback/details/758875/-testtools-unittesting-class-deriv

Leave a Reply

Your email address will not be published. Required fields are marked *