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

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

Sample code in framework\'s AssemblyInfo.cs:

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


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 20:02

    I think it's perfectly reasonable to do that.

    I find it very useful for dependency injection. If I have a class with a constructor that takes in a few dependencies to allow it to be unit tested I often mark it internal and expose it in my unit test project. Then I'd have a public (parameterless, or at least with far fewer parameters) constructor. This keeps the public interface clean and still allows for testable code.

提交回复
热议问题