“Object reference not set to an instance of an object” error in a test project

I was doing what all the cool kids were doing these days, test-driven development. Just the name sparks excitement and intrigue, and makes me want to travel to exotic locations sipping martinis that have been shaken, not stirred. But instead, I’ll probably sit here and look at cube walls.

In my test project, I wrote a test to verify that my connection string exists:

public void Verify_connection_string_exists()

Beautiful. But when I ran my test, I got this message: Object reference not set to an instance of an object.

I tried not to take this personally. After all, unit tests generally don’t have a dislike for an individual programmer, they hate all programmers equally. In this case, I had the minor issue of not having an App.config file in my test project, so the ConfigurationManager class had nothing to pull from.

So, I dragged and dropped the web.config file from the web project I was testing into my test project and renamed it App.config in test project.

And that was it. Once I ran the code again, my simple mistake was erased, never to be heard from again until I forget to include my config file in my project and need this post to remind me.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: