Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm working on a sharepoint project, and the associated visual studio solution contains several projects, of which some are plain c# class libraries. I would like to unit test those projects, but each time I deploy the sharepoint solution the library assemblies are installed to the GAC. Because of this, and the fact that GAC assemblies take precedence over local builds, changes I make to the library project aren't tested until the sharepoint solution is re-deployed. Re-deployment is time consuming, and I don't want to do it each time I edit the code. I tried adding a post-build action to automatically install the library's assembly to the GAC, but I couldn't get it to work reliably.

So, how are you guys doing this? Please note that I'm not talking about unit testing against the sharepoint classes. The reason I'm posting this question in the sharepoint section is that in sharepoint projects you repeatedly install assemblies to the GAC, and those assemblies take precedence over assemblies in [project folder]\bin\Debug.

Maybe I'm going about this in the wrong way, and if so, any pointers in the right direction would be appreciated! :)

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You can just remove dlls from GAC on your dev machine. You can do using Windows Explorer - navigate to c:\windows\assembly. If you want automatic solution - when test project is built - use gacutil \u (http://msdn.microsoft.com/en-us/library/aa559881(v=bts.20).aspx) to clear dlls.

When I was working with SP Unit Tests I did it manually using WE, because I needed to deploy only when I had tested well.

share|improve this answer
1  
The key to efficient testing is to make it simple, and to not depend on manual preparation. I want to be able to update my code and then hit a button to re-run the tests. I guess I could try to automate the process of uninstalling from the GAC. Then I would screw up the sharepoint deployment, but maybe that's OK. –  claesv Jun 1 '12 at 13:05
1  
After unit tests you can redeploy and sharepoint will be back to life. Also if you deploy to GAC you need to recycle IIS app pool, cause it loads dll to memory and it's not updated. –  Yuri Leontyev Jun 1 '12 at 14:23
    
While far from ideal, this is sort of what I ended up doing, as it was the easiest to automate. –  claesv Jun 5 '12 at 12:09
add comment

There is no good way around it (as far as I know). I have also found this really impractical. An ok work-around is to increment the assembly version of the assembly under test. But then again you have to remember to reset it. To make this more smooth you can create either some pre-/post build scripts to this automatically or a msbuild script on the build server to ensure that assembly version always is reset...

I would be great if somebody had a better solution...

share|improve this answer
    
OK, that's a downer, but thanks for the input! –  claesv Jun 4 '12 at 6:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.