Monday, January 30, 2012

How to unit test internal types and members

Internal types and members are by default not accessible from a separate unit test project. However this can be overcome by using something known as a Friend Assembly.

A Friend Assembly is an assembly that can access internal types and members of another assembly. So if you have a project A and a project B and you want B to access the internal members of A, then all you need do is to add the following line to the AssemblyInfo.cs file in A.

[assembly: InternalsVisibleTo("B")]