Geeks With Blogs
Reidar Husmo SharePoint from the trenches

Unit testing SharePoint is difficult for a number of reasons.

One of the better known ones is perhaps that of the GAC; the .net loader ("Fusion") will use assemblies from the GAC even if you specify the full path to the newly-built-but-not-yet-tested-dll.

If you are unaware of this, it can be an extremely frustrating experience - or so I've been told... ("...but... how can that code possibly still be wrong?! I've commented it all out!")

In the past I've attempted daft things like renaming the dll to "something that has never been gacced" (ie. <whatever>2.dll), and adding that dll as a reference in my test project. (in case you want to know: No, it doesn't work)

Today I came across a better way in a presentation by Bill Ayers. And by better, I mean it actually works.

Briefly: In the test project, "add as a link" the class you want to test. ("Add existing item...", browse to the cs file in the SharePoint project, select it, and add as link - it's a drop-down button.)

Of course, the linked cs-file is now (also) a part of the test-project, so if the file makes calls to code in other files, they have to be linked to, too. Etc.


Posted on Wednesday, February 6, 2013 9:25 PM | Back to top


Comments on this post: Use "Add as link" to unit test SharePoint

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Norgean | Powered by: GeeksWithBlogs.net