Writing unit tests for signed assemblies in .NET and the InternalsVisibleTo attribute
In order to write unit tests for class marked as internal you will have to add InternalsVisibleTo attribute to your signed assembly, in order to expose those classes to the unit tests project. That poses a problem when the assembly you are testing is signed, and most likely you will get an error with a similar message “Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations”.
To solve the problem and continue on your way of testing your classes, simply sign your unit test project, and then add the public key to the InternalsVisibleTo declaration. Something like:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("TestAssembly, PublicKey=......")]
Notice the fact that the public key reference is specified with only “PublicKey” and not with “PublicKeyToken”, which is what you would use if you normally reference a signed assembly.
Categories
Archives
Software Quotes
??Software Blogs
February 2012 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29





