Growing with the Web

Hide your testing methods using InternalsVisibleTo


It is not necessary to expose all methods being tested as public when using an external test project. By using the assembly attribute InternalsVisibleTo and specifying the namespace of the “friend” assembly, the visibility of the methods can then be reduced to internal, hiding them from all other assemblies.

In the project’s AssemblyInfo.cs

[assembly: InternalsVisibleTo("MyAssembly.Tests")]

Like this article?
Subscribe for more!