Sunday, April 15, 2012

Missing Method Exception (or why my Unit Tests would not work with my SharePoint project)

I'm using some test driven development concepts on a little SharePoint development project.

I noticed that I kept running into a really strange error every time I added a new Method to my SharePoint project.

Whenever I would run my new Unit Test I would get a System.MissingMethodException error saying that the method in my SharePoint project could not be found.

Turns out that the problem was caused by the fact that the Unit Test project was loading my SharePoint assembly from the GAC.  So for me to get the tests to work I had to install the latest version of my SharePoint assembly into the GAC and then close/open Visual Studio.

I like to take very small steps when I develop (add some functionality, test it, add some functionality, test it).  So the idea of constantly updating the GAC and closing Visual Studio was not appealing.

I considered removing my SharePoint assembly from the GAC, but I put it in there for some legitimate reasons.

After much trial and error I found a solution that works okay (but is not ideal).  I configured my Unit Test project to install the SharePoint dll in the GAC whenever the project is compiled.  And I run the Unit Tests in Debug mode.  With this setup I am able to get instant feedback from my changes.

As I said it is not ideal, but works.

To install my SharePoint dll in the GAC I added a Post Build event to my Unit Test project.  It just runs the gacutil command.

To run my Unit Tests in debug mode I launch my tests using the Visual Studio Debug option rather than Run option.

VSNET_UnitTest_SnapShot

I am using Visual Studio 2008 Test project for my Unit Tests.


View the original article here

No comments:

Post a Comment