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

后端 未结 5 1693
说谎
说谎 2020-12-04 09:51

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 ?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 10:26

    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.

提交回复
热议问题