.

Unit Testing Cross Assemblies with “internal” declarations

The steps to allow access to external assemblies mainly for testing purposes:

  1. Navigate to your tests assembly / project.
  2. double click on the properties folder.
  3. copy the full assembly name - e.g. Bitlink.Chess.OpeningExplorer.Tests
  4. go to your assembly that you want to test (the one which uses internal declarations)
    in my case: Bitlink.Chess.OpeningExplorer.Library
  5. expand the properties folder, locate and open AssemblyInfo.cs
  6. at the very bottom of this file, put a reference to your test assembly, e.g.:
    [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Bitlink.Chess.OpeningExplorer.Tests")]

if you have signed your assemblies, you would need a further signature:

[assembly: InternalsVisibleTo("...Tests")] , PublicKey=……

for that you could extract the public key token of your keyfile over two steps

  1. extract the public key from the keyfile with
    sn –p <keyfile.snk> <keyfile.snk.PublicKey>
  2. show the public key token with
    sn -t <keyfile.snk.PublicKey>

or use the GetPublicKey utility that’s going around:  download GetPublicKey

What's your thoughts on this?

*

Protected by WP Anti Spam