Is it considered bad practice to use InternalsVisibleTo for Unit Test Code?

后端 未结 6 1212
余生分开走
余生分开走 2021-01-03 19:39

Sample code in framework\'s AssemblyInfo.cs:

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo
                          (\"Test.Com         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 20:10

    InternalsVisibleTo could be useful if you need to test sub parts of your API which you don't want to expose.

    However, testing through the public API is preferable since it makes refactoring interal APIs easier. Use InternalsVisibleTo with care and only when appropriate, e.g. the size of the API is significant.

提交回复
热议问题