Unit testing assemblies with internals

How do you unit test an assembly if the vast majority of its methods are declared “internal” (in C#)? Before today, I had no idea. Fortunately for me, one of my consultants had this exact problem last year. The solution:

[assembly: InternalsVisibleTo(“UnitTestAssemblyName”)]

Putting the following line in AssemblyInfo.cs for the assembly you wish to unit test makes everything declared “internal” available to UnitTestAssemblyName.

This is a vastly superior option to cloning the assembly you want to test and making all the internal members public.

Comments

  1. Rob Henry says:

    “InternalsVisibleTo”

    Nice. Thanks.

    Definitely needed for testing Internal classes and other members.

Leave a Reply to Rob Henry Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.