Search code examples
.netunit-testing

How do I allow assembly (unit testing one) to access internal properties of another assembly?


I would like my Core assembly to not expose a certain class and I would still like to be able to test it. How can I do that ?


Solution

  • InternalsVisibleTo attribute to the rescue!

    Just add:

    [assembly:InternalsVisibleToAttribute("UnitTestAssemblyName")]
    

    to your Core classes AssemblyInfo.cs file

    See Friend Assemblies (C# Programming Guide) for best practices.