views:

317

answers:

1

Hi Everyone.

I'm getting a strange error when I try to run a set of unit tests where the class has a DeploymentItem attribute.

The unit testing solution has 2 test classes, one to test business logic which I'll refer to as 'class a' (this one works fine regardless) and one to test reading of data from the DeploymentItem file which I'll refer to as 'class b'.

With the DeploymentItem attribute set ANYWHERE within the two test classes, the tests in class b all fail with the error...

Unable to create instance of class [class b]. Error: System.NullReferenceException: Object reference not set to an instance of an object..

However, if I completely remove the DeploymentItem attribute from both classes, all tests run, but obviously fail in class b because there is no file to read from, therefore all asserts fail.

I hope I've explained the problem fully, if not I should be able to clarify more if required. Very grateful for any help.

+2  A: 

A quick guess: Have you checked the Enable deployment checkbox in your .testrunconfig file? If not, DeploymentItemAttribute is not going to work.

Not sure whether it will give you that exception, though, but it's worth checking out.

Mark Seemann
Hi Mark,Thanks for taking the time to reply.Yes the Enable deployment checkbox is checked in the testrunconfig file and has been all along.Any other thoughts?
Jason Summers
Does the stack trace tell you anything?
Mark Seemann