4

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! :)

2 Answers 2

2

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.

3
  • 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
    Commented Jun 1, 2012 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. Commented Jun 1, 2012 at 14:23
  • While far from ideal, this is sort of what I ended up doing, as it was the easiest to automate.
    – claesv
    Commented Jun 5, 2012 at 12:09
0

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...

1
  • OK, that's a downer, but thanks for the input!
    – claesv
    Commented Jun 4, 2012 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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